mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 09:48:00 +01:00
Improve :bmarks completer. Fix shaky completion display code.
This commit is contained in:
@@ -282,7 +282,7 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
function tags(context, args)
|
function tags(context, args)
|
||||||
{
|
{
|
||||||
let filter = args.completeFilter;
|
let filter = context.filter;
|
||||||
let have = filter.split(",");
|
let have = filter.split(",");
|
||||||
args.completeFilter = have.pop();
|
args.completeFilter = have.pop();
|
||||||
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
|
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
|
||||||
@@ -325,7 +325,7 @@ function Bookmarks() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
bang: true,
|
bang: true,
|
||||||
completer: function (context, args) completion.url(context, "b"),
|
completer: function (context, args) completion.bookmark(context, args["-tags"]),
|
||||||
options: [[["-tags", "-T"], commands.OPTION_LIST, null, tags]]
|
options: [[["-tags", "-T"], commands.OPTION_LIST, null, tags]]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ function Bookmarks() //{{{
|
|||||||
liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE);
|
liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (context) completion.bookmark(context.filter),
|
completer: function (context) completion.bookmark(context),
|
||||||
literal: true
|
literal: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -989,9 +989,10 @@ function Completion() //{{{
|
|||||||
let filterTokens = filter.split(/\s+/);
|
let filterTokens = filter.split(/\s+/);
|
||||||
for (let [,elem] in Iterator(urls))
|
for (let [,elem] in Iterator(urls))
|
||||||
{
|
{
|
||||||
var url = elem.url || "";
|
let item = elem.item || elem; // Kludge
|
||||||
var title = elem.title || "";
|
var url = item.url || "";
|
||||||
var tags = elem.tags || [];
|
var title = item.title || "";
|
||||||
|
var tags = item.tags || [];
|
||||||
if (ignorecase)
|
if (ignorecase)
|
||||||
{
|
{
|
||||||
url = url.toLowerCase();
|
url = url.toLowerCase();
|
||||||
@@ -1048,11 +1049,18 @@ function Completion() //{{{
|
|||||||
|
|
||||||
autocmdEvent: function autocmdEvent(filter) [0, this.filter(config.autocommands, filter)],
|
autocmdEvent: function autocmdEvent(filter) [0, this.filter(config.autocommands, filter)],
|
||||||
|
|
||||||
bookmark: function bookmark(context)
|
bookmark: function bookmark(context, tags)
|
||||||
{
|
{
|
||||||
context.title = ["Bookmark", "Title"];
|
context.title = ["Bookmark", "Title"];
|
||||||
context.format = bookmarks.format;
|
context.format = bookmarks.format;
|
||||||
context.completions = bookmarks.get(context.filter)
|
context.completions = bookmarks.get(context.filter)
|
||||||
|
if (tags)
|
||||||
|
{
|
||||||
|
let filterFunc = context.filterFunc;
|
||||||
|
context.filterFunc = function (items, filter, anchored)
|
||||||
|
filterFunc.call(this, items, filter, anchored)
|
||||||
|
.filter(function ({item: item}) tags.every(function (tag) item.tags.indexOf(tag) > -1));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
buffer: function buffer(filter)
|
buffer: function buffer(filter)
|
||||||
@@ -1171,29 +1179,32 @@ function Completion() //{{{
|
|||||||
// dynamically get completions as specified with the command's completer function
|
// dynamically get completions as specified with the command's completer function
|
||||||
let command = commands.get(cmd);
|
let command = commands.get(cmd);
|
||||||
let compObject = { start: 0, items: [] };
|
let compObject = { start: 0, items: [] };
|
||||||
if (command)
|
if (!command)
|
||||||
{
|
{
|
||||||
[prefix] = context.filter.match(/^(?:\w*[\s!]|!)\s*/);
|
context.highlight(0, cmd.length, "SPELLCHECK");
|
||||||
let cmdContext = context.fork(cmd, prefix.length);
|
return;
|
||||||
let argContext = cmdContext.fork("args", args.completeStart);
|
}
|
||||||
args = command.parseArgs(cmdContext.filter, argContext);
|
|
||||||
if (args)
|
[prefix] = context.filter.match(/^(?:\w*[\s!]|!)\s*/);
|
||||||
|
let cmdContext = context.fork(cmd, prefix.length);
|
||||||
|
let argContext = cmdContext.fork("args", args.completeStart);
|
||||||
|
args = command.parseArgs(cmdContext.filter, argContext);
|
||||||
|
if (args)
|
||||||
|
{
|
||||||
|
if (!args.completeOpt && command.completer)
|
||||||
{
|
{
|
||||||
if (!args.completeOpt && command.completer)
|
cmdContext.advance(args.completeStart);
|
||||||
|
compObject = command.completer.call(command, cmdContext, args, special, count);
|
||||||
|
if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects
|
||||||
|
compObject = { start: compObject[0], items: compObject[1] };
|
||||||
|
if (compObject != null)
|
||||||
{
|
{
|
||||||
cmdContext.advance(args.completeStart);
|
cmdContext.advance(compObject.start);
|
||||||
compObject = command.completer.call(command, cmdContext, args, special, count);
|
cmdContext.filterFunc = null;
|
||||||
if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects
|
cmdContext.completions = compObject.items;
|
||||||
compObject = { start: compObject[0], items: compObject[1] };
|
|
||||||
if (compObject != null)
|
|
||||||
{
|
|
||||||
cmdContext.advance(compObject.start);
|
|
||||||
cmdContext.filterFunc = null;
|
|
||||||
cmdContext.completions = compObject.items;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
context.updateAsync = true;
|
|
||||||
}
|
}
|
||||||
|
context.updateAsync = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1282,6 +1282,9 @@ function ItemList(id) //{{{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dom(xml) util.xmlToDom(xml, doc);
|
||||||
|
function elemToString(elem) elem.nodeType == elem.TEXT_NODE ? elem.data :
|
||||||
|
"<" + [elem.localName].concat([a.name + "=" + a.value.quote() for (a in util.Array.iterator(elem.attributes))]).join(" ") + ">";
|
||||||
var doc = iframe.contentDocument;
|
var doc = iframe.contentDocument;
|
||||||
var container = iframe.parentNode;
|
var container = iframe.parentNode;
|
||||||
|
|
||||||
@@ -1296,7 +1299,6 @@ function ItemList(id) //{{{
|
|||||||
var noCompletions = null;
|
var noCompletions = null;
|
||||||
var completionBody = null;
|
var completionBody = null;
|
||||||
var minHeight = 0;
|
var minHeight = 0;
|
||||||
var div = null;
|
|
||||||
|
|
||||||
function autoSize()
|
function autoSize()
|
||||||
{
|
{
|
||||||
@@ -1313,7 +1315,6 @@ function ItemList(id) //{{{
|
|||||||
|
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
function dom(xml) util.xmlToDom(xml, doc);
|
|
||||||
div = dom(
|
div = dom(
|
||||||
<div class="ex-command-output hl-Normal" style="white-space: nowrap">
|
<div class="ex-command-output hl-Normal" style="white-space: nowrap">
|
||||||
<div class="hl-Completions"><span class="hl-Title">No Completions</span></div>
|
<div class="hl-Completions"><span class="hl-Title">No Completions</span></div>
|
||||||
@@ -1325,8 +1326,9 @@ function ItemList(id) //{{{
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>);
|
</div>);
|
||||||
noCompletions = div.childNodes[1];
|
|
||||||
completionBody = div.childNodes[3];
|
noCompletions = div.getElementsByTagName("div")[0];
|
||||||
|
completionBody = div.getElementsByTagName("div")[1];
|
||||||
items.contextList.forEach(function (context) {
|
items.contextList.forEach(function (context) {
|
||||||
if (!context.items.length)
|
if (!context.items.length)
|
||||||
return;
|
return;
|
||||||
@@ -1348,7 +1350,7 @@ function ItemList(id) //{{{
|
|||||||
*/
|
*/
|
||||||
function fill(offset)
|
function fill(offset)
|
||||||
{
|
{
|
||||||
function dom(xml) util.xmlToDom(xml, doc);
|
XML.ignoreWhiteSpace = false;
|
||||||
let diff = offset - startIndex;
|
let diff = offset - startIndex;
|
||||||
if (items == null || offset == null || diff == 0 || offset < 0)
|
if (items == null || offset == null || diff == 0 || offset < 0)
|
||||||
return;
|
return;
|
||||||
@@ -1358,7 +1360,6 @@ function ItemList(id) //{{{
|
|||||||
startIndex = offset;
|
startIndex = offset;
|
||||||
endIndex = Math.min(startIndex + maxItems, items.allItems.items.length);
|
endIndex = Math.min(startIndex + maxItems, items.allItems.items.length);
|
||||||
|
|
||||||
XML.ignoreWhitespace = true;
|
|
||||||
let off = 0;
|
let off = 0;
|
||||||
function getRows(context)
|
function getRows(context)
|
||||||
{
|
{
|
||||||
@@ -1375,17 +1376,18 @@ function ItemList(id) //{{{
|
|||||||
let d = stuff.cloneNode(true);
|
let d = stuff.cloneNode(true);
|
||||||
for (let [,row] in Iterator(getRows(context)))
|
for (let [,row] in Iterator(getRows(context)))
|
||||||
d.appendChild(row);
|
d.appendChild(row);
|
||||||
dom.replaceChild(d, dom.childNodes[3]);
|
|
||||||
|
//liberator.dump(util.map(util.range(0, dom.childNodes.length), function (i) elemToString(dom.childNodes[i])));
|
||||||
|
|
||||||
|
dom.replaceChild(d, dom.childNodes[3] || dom.childNodes[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
noCompletions.style.display = off > 0 ? "none" : "block";
|
noCompletions.style.display = off > 0 ? "none" : "block";
|
||||||
} catch(e) {}
|
|
||||||
|
|
||||||
let dom = div.cloneNode(true);
|
let node = div.cloneNode(true);
|
||||||
completionElements = dom.getElementsByClassName("hl-CompItem");
|
completionElements = node.getElementsByClassName("hl-CompItem");
|
||||||
completionBody = dom.childNodes[3];
|
completionBody = node.getElementsByTagName("div")[1];
|
||||||
doc.body.replaceChild(dom, doc.body.firstChild);
|
doc.body.replaceChild(node, doc.body.firstChild);
|
||||||
|
|
||||||
autoSize();
|
autoSize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ const util = { //{{{
|
|||||||
/* minInterval is the time between the completion of the command and the next firing. */
|
/* minInterval is the time between the completion of the command and the next firing. */
|
||||||
this.doneAt = Date.now() + minInterval;
|
this.doneAt = Date.now() + minInterval;
|
||||||
|
|
||||||
liberator.dump({notify: "notify"});
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
callback(this.arg);
|
callback(this.arg);
|
||||||
|
|||||||
Reference in New Issue
Block a user