diff --git a/content/bookmarks.js b/content/bookmarks.js index 20c8b7db..378a05c9 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -282,7 +282,7 @@ function Bookmarks() //{{{ function tags(context, args) { - let filter = args.completeFilter; + let filter = context.filter; let have = filter.split(","); args.completeFilter = have.pop(); let prefix = filter.substr(0, filter.length - args.completeFilter.length); @@ -325,7 +325,7 @@ function Bookmarks() //{{{ }, { 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]] }); @@ -339,7 +339,7 @@ function Bookmarks() //{{{ 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 }); diff --git a/content/completion.js b/content/completion.js index af96035a..5a5bba92 100644 --- a/content/completion.js +++ b/content/completion.js @@ -989,9 +989,10 @@ function Completion() //{{{ let filterTokens = filter.split(/\s+/); for (let [,elem] in Iterator(urls)) { - var url = elem.url || ""; - var title = elem.title || ""; - var tags = elem.tags || []; + let item = elem.item || elem; // Kludge + var url = item.url || ""; + var title = item.title || ""; + var tags = item.tags || []; if (ignorecase) { url = url.toLowerCase(); @@ -1048,11 +1049,18 @@ function Completion() //{{{ autocmdEvent: function autocmdEvent(filter) [0, this.filter(config.autocommands, filter)], - bookmark: function bookmark(context) + bookmark: function bookmark(context, tags) { context.title = ["Bookmark", "Title"]; context.format = bookmarks.format; 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) @@ -1171,29 +1179,32 @@ function Completion() //{{{ // dynamically get completions as specified with the command's completer function let command = commands.get(cmd); let compObject = { start: 0, items: [] }; - if (command) + if (!command) { - [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) + context.highlight(0, cmd.length, "SPELLCHECK"); + return; + } + + [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); - 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(compObject.start); - cmdContext.filterFunc = null; - cmdContext.completions = compObject.items; - } + cmdContext.advance(compObject.start); + cmdContext.filterFunc = null; + cmdContext.completions = compObject.items; } - context.updateAsync = true; } + context.updateAsync = true; } }, diff --git a/content/ui.js b/content/ui.js index 07d1b82f..7db9d2fe 100644 --- a/content/ui.js +++ b/content/ui.js @@ -1282,6 +1282,9 @@ function ItemList(id) //{{{ 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 container = iframe.parentNode; @@ -1296,7 +1299,6 @@ function ItemList(id) //{{{ var noCompletions = null; var completionBody = null; var minHeight = 0; - var div = null; function autoSize() { @@ -1313,7 +1315,6 @@ function ItemList(id) //{{{ function init() { - function dom(xml) util.xmlToDom(xml, doc); div = dom(
No Completions
@@ -1325,8 +1326,9 @@ function ItemList(id) //{{{ }
); - noCompletions = div.childNodes[1]; - completionBody = div.childNodes[3]; + + noCompletions = div.getElementsByTagName("div")[0]; + completionBody = div.getElementsByTagName("div")[1]; items.contextList.forEach(function (context) { if (!context.items.length) return; @@ -1348,7 +1350,7 @@ function ItemList(id) //{{{ */ function fill(offset) { - function dom(xml) util.xmlToDom(xml, doc); + XML.ignoreWhiteSpace = false; let diff = offset - startIndex; if (items == null || offset == null || diff == 0 || offset < 0) return; @@ -1358,7 +1360,6 @@ function ItemList(id) //{{{ startIndex = offset; endIndex = Math.min(startIndex + maxItems, items.allItems.items.length); - XML.ignoreWhitespace = true; let off = 0; function getRows(context) { @@ -1375,17 +1376,18 @@ function ItemList(id) //{{{ let d = stuff.cloneNode(true); for (let [,row] in Iterator(getRows(context))) 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"; - } catch(e) {} - let dom = div.cloneNode(true); - completionElements = dom.getElementsByClassName("hl-CompItem"); - completionBody = dom.childNodes[3]; - doc.body.replaceChild(dom, doc.body.firstChild); + let node = div.cloneNode(true); + completionElements = node.getElementsByClassName("hl-CompItem"); + completionBody = node.getElementsByTagName("div")[1]; + doc.body.replaceChild(node, doc.body.firstChild); autoSize(); } diff --git a/content/util.js b/content/util.js index 28e8475b..f0b66b7a 100644 --- a/content/util.js +++ b/content/util.js @@ -89,7 +89,6 @@ const util = { //{{{ /* minInterval is the time between the completion of the command and the next firing. */ this.doneAt = Date.now() + minInterval; - liberator.dump({notify: "notify"}); try { callback(this.arg);