diff --git a/content/commands.js b/content/commands.js index 724b40ef..fe8f1b30 100644 --- a/content/commands.js +++ b/content/commands.js @@ -456,6 +456,7 @@ function Commands() //{{{ argCount = "*"; var args = []; // parsed options + args.__iterator__ = util.Array.iterator2; args.string = str; // for access to the unparsed string args.literalArg = ""; diff --git a/content/completion.js b/content/completion.js index 82bea015..abe2dfe4 100644 --- a/content/completion.js +++ b/content/completion.js @@ -75,8 +75,8 @@ function CompletionContext(editor, name, offset) this.filterFunc = function (items) { let self = this; - return this.filters.reduce(function (res, filter) - res.filter(function (item) filter.call(self, item)), + return this.filters.reduce( + function (res, filter) res.filter(function (item) filter.call(self, item)), items); } this.filters = [function (item) { @@ -120,6 +120,7 @@ CompletionContext.prototype = { }); return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring } }, + // Temporary get allSubstrings() { let self = this; @@ -132,16 +133,19 @@ CompletionContext.prototype = { }); return util.Array.uniq(util.Array.flatten(items), true); }, + // Temporary get longestAllSubstring() { let substrings = this.allSubstrings; - return substrings.reduce(function (res, str) - res.filter(function (s) { + // Filter out any matches that don't match for all contexts + substrings = substrings.reduce( + function (res, str) res.filter(function (s) { let len = Math.min(s.length, str.length); return str.substr(0, len) == s.substr(0, len) }), - substrings) - .reduce(function (a, b) a.length > b.length ? a : b, ""); + substrings); + // Find the longest match + return substrings.reduce(function (a, b) a.length > b.length ? a : b, ""); }, get caret() (this.editor ? this.editor.selection.getRangeAt(0).startOffset : this.value.length) - this.offset, @@ -300,8 +304,8 @@ CompletionContext.prototype = { start = idx + 1; } } - substrings = items.reduce(function (res, item) - res.filter(function (str) compare(fixCase(item.unquoted || item.text), str)), + substrings = items.reduce( + function (res, item) res.filter(function (str) compare(fixCase(item.unquoted || item.text), str)), substrings); let quote = this.quote; if (quote) @@ -340,8 +344,8 @@ CompletionContext.prototype = { let reverse = start > end; start = Math.max(0, start || 0); end = Math.min(items.length, end != null ? end : items.length); - return util.map(util.range(start, end, reverse), - function (i) cache[i] = cache[i] || util.xmlToDom(self.createRow(items[i]), doc)); + for (let i in util.range(start, end, reverse)) + yield [i, cache[i] = cache[i] || util.xmlToDom(self.createRow(items[i]), doc)]; }, fork: function fork(name, offset, self, completer) @@ -441,12 +445,6 @@ function Completion() //{{{ const cleanEval = _cleanEval; delete modules._cleanEval; - // the completion substrings, used for showing the longest common match - var cacheFilter = {} - var cacheResults = {} - var substrings = []; - var historyCache = []; - function Javascript() { let json = Components.classes["@mozilla.org/dom/json;1"] @@ -953,12 +951,6 @@ function Completion() //{{{ } }, - // returns the longest common substring - // used for the 'longest' setting for wildmode - get longestSubstring() substrings.reduce(function (a, b) a.length > b.length ? a : b, ""), - - get substrings() substrings.slice(), - runCompleter: function (name, filter) { let context = CompletionContext(filter); @@ -1170,15 +1162,6 @@ function Completion() //{{{ // provides completions for ex commands, including their arguments ex: function ex(context) { - this.filterMap = null; - substrings = []; - if (context.filter.indexOf(cacheFilter["ex"]) != 0) - { - cacheFilter = {}; - cacheResults = {}; - } - cacheFilter["ex"] = context.filter; - // if there is no space between the command name and the cursor // then get completions of the command name let [count, cmd, bang, args] = commands.parseCommand(context.filter); diff --git a/content/options.js b/content/options.js index ae3f255e..c0661ba8 100644 --- a/content/options.js +++ b/content/options.js @@ -786,7 +786,7 @@ function Options() //{{{ //var length = names.length; //for (let i = 0, name = names[i]; i < length; name = names[++i]) - for (let [,name] in Iterator(args)) + for (let [,name] in args) { var name = args[i]; var reference = liberator.variableReference(name); diff --git a/content/style.js b/content/style.js index 63ba5ef0..621c9c27 100644 --- a/content/style.js +++ b/content/style.js @@ -37,7 +37,7 @@ function Highlights(name, store, serial) CompIcon>img max-width: 16px; max-height: 16px; vertical-align: middle; CompResult width: 45%; overflow: hidden; CompDesc color: gray; width: 50%; - CompLess text-align: center; height: .5ex; line-height: .5ex; + CompLess text-align: center; height: .5ex; line-height: .5ex; padding-top: 1ex; CompLess:after content: "\2303" /* Unicode up arrowhead */ CompMore text-align: center; height: .5ex; line-height: .5ex; CompMore:after content: "\2304" /* Unicode down arrowhead */ diff --git a/content/ui.js b/content/ui.js index c78cc3e5..de0de3e7 100644 --- a/content/ui.js +++ b/content/ui.js @@ -1310,7 +1310,7 @@ function ItemList(id) //{{{ commandline.updateOutputHeight(false); } - function getCompletion(index) completionElements[index - startIndex]; + function getCompletion(index) completionElements.snapshotItem(index - startIndex); function init() { @@ -1328,15 +1328,16 @@ function ItemList(id) //{{{ doc.body.replaceChild(div, doc.body.firstChild); items.contextList.forEach(function init_eachContext(context) { + delete context.cache.nodes; if (!context.items.length) return; - context.cache.nodes = {}; + context.cache.nodes = []; dom(
{context.createRow(context.title || [], "hl-CompTitle")}
-
+
, context.cache.nodes); divNodes.completions.appendChild(context.cache.nodes.root); @@ -1356,8 +1357,6 @@ function ItemList(id) //{{{ if (items == null || offset == null || diff == 0 || offset < 0) return false; - let stuff = dom(
); - startIndex = offset; endIndex = Math.min(startIndex + maxItems, items.allItems.items.length); @@ -1375,20 +1374,33 @@ function ItemList(id) //{{{ let nodes = context.cache.nodes; if (!nodes) return; - let dom = nodes.root + let root = nodes.root + let items = nodes.items; let [start, end] = getRows(context); - let d = stuff.cloneNode(true); - for (let [,row] in Iterator(context.getRows(start, end, doc))) - d.appendChild(row); - dom.replaceChild(d, nodes.items); - nodes.items = d; + for (let [i, row] in Iterator(context.getRows(start, end, doc))) + nodes[i] = row; + for (let [i, row] in util.Array.iterator2(nodes)) + { + let display = i >= start && i < end; + if (row.parentNode != items) + { + do + var next = nodes[++i]; + while ((!next || next.parentNode != root) && i < nodes.length); + items.insertBefore(row, next); + } + if (display) + delete row.style.display; + else + row.style.display = "none"; + } nodes.up.style.display = (start == 0) ? "none" : "block"; nodes.down.style.display = (end == context.items.length) ? "none" : "block"; }); divNodes.noCompletions.style.display = (off > 0) ? "none" : "block"; - completionElements = div.getElementsByClassName("hl-CompItem"); + completionElements = buffer.evaluateXPath("//*[@class='hl-CompItem' and not(contains(@style, 'none'))]", doc); autoSize(); return true; diff --git a/content/util.js b/content/util.js index 1bc41d73..574c1975 100644 --- a/content/util.js +++ b/content/util.js @@ -48,6 +48,13 @@ const util = { //{{{ yield ary[i]; }, + iterator2: function (ary) + { + let length = ary.length; + for (let i = 0; i < length; i++) + yield [i, ary[i]]; + }, + uniq: function (ary, unsorted) { let ret = [];