1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 10:47:59 +01:00

Speed up completion scrolling more.

This commit is contained in:
Kris Maglione
2008-11-27 01:18:33 +00:00
parent 424909162d
commit 0eafcd8656
6 changed files with 48 additions and 45 deletions

View File

@@ -456,6 +456,7 @@ function Commands() //{{{
argCount = "*"; argCount = "*";
var args = []; // parsed options var args = []; // parsed options
args.__iterator__ = util.Array.iterator2;
args.string = str; // for access to the unparsed string args.string = str; // for access to the unparsed string
args.literalArg = ""; args.literalArg = "";

View File

@@ -75,8 +75,8 @@ function CompletionContext(editor, name, offset)
this.filterFunc = function (items) this.filterFunc = function (items)
{ {
let self = this; let self = this;
return this.filters.reduce(function (res, filter) return this.filters.reduce(
res.filter(function (item) filter.call(self, item)), function (res, filter) res.filter(function (item) filter.call(self, item)),
items); items);
} }
this.filters = [function (item) { this.filters = [function (item) {
@@ -120,6 +120,7 @@ CompletionContext.prototype = {
}); });
return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring } return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring }
}, },
// Temporary
get allSubstrings() get allSubstrings()
{ {
let self = this; let self = this;
@@ -132,16 +133,19 @@ CompletionContext.prototype = {
}); });
return util.Array.uniq(util.Array.flatten(items), true); return util.Array.uniq(util.Array.flatten(items), true);
}, },
// Temporary
get longestAllSubstring() get longestAllSubstring()
{ {
let substrings = this.allSubstrings; let substrings = this.allSubstrings;
return substrings.reduce(function (res, str) // Filter out any matches that don't match for all contexts
res.filter(function (s) { substrings = substrings.reduce(
function (res, str) res.filter(function (s) {
let len = Math.min(s.length, str.length); let len = Math.min(s.length, str.length);
return str.substr(0, len) == s.substr(0, len) return str.substr(0, len) == s.substr(0, len)
}), }),
substrings) substrings);
.reduce(function (a, b) a.length > b.length ? a : b, ""); // 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, get caret() (this.editor ? this.editor.selection.getRangeAt(0).startOffset : this.value.length) - this.offset,
@@ -300,8 +304,8 @@ CompletionContext.prototype = {
start = idx + 1; start = idx + 1;
} }
} }
substrings = items.reduce(function (res, item) substrings = items.reduce(
res.filter(function (str) compare(fixCase(item.unquoted || item.text), str)), function (res, item) res.filter(function (str) compare(fixCase(item.unquoted || item.text), str)),
substrings); substrings);
let quote = this.quote; let quote = this.quote;
if (quote) if (quote)
@@ -340,8 +344,8 @@ CompletionContext.prototype = {
let reverse = start > end; let reverse = start > end;
start = Math.max(0, start || 0); start = Math.max(0, start || 0);
end = Math.min(items.length, end != null ? end : items.length); end = Math.min(items.length, end != null ? end : items.length);
return util.map(util.range(start, end, reverse), for (let i in util.range(start, end, reverse))
function (i) cache[i] = cache[i] || util.xmlToDom(self.createRow(items[i]), doc)); yield [i, cache[i] = cache[i] || util.xmlToDom(self.createRow(items[i]), doc)];
}, },
fork: function fork(name, offset, self, completer) fork: function fork(name, offset, self, completer)
@@ -441,12 +445,6 @@ function Completion() //{{{
const cleanEval = _cleanEval; const cleanEval = _cleanEval;
delete modules._cleanEval; delete modules._cleanEval;
// the completion substrings, used for showing the longest common match
var cacheFilter = {}
var cacheResults = {}
var substrings = [];
var historyCache = [];
function Javascript() function Javascript()
{ {
let json = Components.classes["@mozilla.org/dom/json;1"] 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) runCompleter: function (name, filter)
{ {
let context = CompletionContext(filter); let context = CompletionContext(filter);
@@ -1170,15 +1162,6 @@ function Completion() //{{{
// provides completions for ex commands, including their arguments // provides completions for ex commands, including their arguments
ex: function ex(context) 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 // if there is no space between the command name and the cursor
// then get completions of the command name // then get completions of the command name
let [count, cmd, bang, args] = commands.parseCommand(context.filter); let [count, cmd, bang, args] = commands.parseCommand(context.filter);

View File

@@ -786,7 +786,7 @@ function Options() //{{{
//var length = names.length; //var length = names.length;
//for (let i = 0, name = names[i]; i < length; name = names[++i]) //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 name = args[i];
var reference = liberator.variableReference(name); var reference = liberator.variableReference(name);

View File

@@ -37,7 +37,7 @@ function Highlights(name, store, serial)
CompIcon>img max-width: 16px; max-height: 16px; vertical-align: middle; CompIcon>img max-width: 16px; max-height: 16px; vertical-align: middle;
CompResult width: 45%; overflow: hidden; CompResult width: 45%; overflow: hidden;
CompDesc color: gray; width: 50%; 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 */ CompLess:after content: "\2303" /* Unicode up arrowhead */
CompMore text-align: center; height: .5ex; line-height: .5ex; CompMore text-align: center; height: .5ex; line-height: .5ex;
CompMore:after content: "\2304" /* Unicode down arrowhead */ CompMore:after content: "\2304" /* Unicode down arrowhead */

View File

@@ -1310,7 +1310,7 @@ function ItemList(id) //{{{
commandline.updateOutputHeight(false); commandline.updateOutputHeight(false);
} }
function getCompletion(index) completionElements[index - startIndex]; function getCompletion(index) completionElements.snapshotItem(index - startIndex);
function init() function init()
{ {
@@ -1328,15 +1328,16 @@ function ItemList(id) //{{{
doc.body.replaceChild(div, doc.body.firstChild); doc.body.replaceChild(div, doc.body.firstChild);
items.contextList.forEach(function init_eachContext(context) { items.contextList.forEach(function init_eachContext(context) {
delete context.cache.nodes;
if (!context.items.length) if (!context.items.length)
return; return;
context.cache.nodes = {}; context.cache.nodes = [];
dom(<div key="root"> dom(<div key="root">
<div class="hl-Completions"> <div class="hl-Completions">
{context.createRow(context.title || [], "hl-CompTitle")} {context.createRow(context.title || [], "hl-CompTitle")}
</div> </div>
<div key="up" class="hl-CompLess"/> <div key="up" class="hl-CompLess"/>
<div key="items"/> <div key="items" class="hl-Completions"/>
<div key="down" class="hl-CompMore"/> <div key="down" class="hl-CompMore"/>
</div>, context.cache.nodes); </div>, context.cache.nodes);
divNodes.completions.appendChild(context.cache.nodes.root); divNodes.completions.appendChild(context.cache.nodes.root);
@@ -1356,8 +1357,6 @@ function ItemList(id) //{{{
if (items == null || offset == null || diff == 0 || offset < 0) if (items == null || offset == null || diff == 0 || offset < 0)
return false; return false;
let stuff = dom(<div class="hl-Completions"/>);
startIndex = offset; startIndex = offset;
endIndex = Math.min(startIndex + maxItems, items.allItems.items.length); endIndex = Math.min(startIndex + maxItems, items.allItems.items.length);
@@ -1375,20 +1374,33 @@ function ItemList(id) //{{{
let nodes = context.cache.nodes; let nodes = context.cache.nodes;
if (!nodes) if (!nodes)
return; return;
let dom = nodes.root let root = nodes.root
let items = nodes.items;
let [start, end] = getRows(context); let [start, end] = getRows(context);
let d = stuff.cloneNode(true); for (let [i, row] in Iterator(context.getRows(start, end, doc)))
for (let [,row] in Iterator(context.getRows(start, end, doc))) nodes[i] = row;
d.appendChild(row); for (let [i, row] in util.Array.iterator2(nodes))
dom.replaceChild(d, nodes.items); {
nodes.items = d; 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.up.style.display = (start == 0) ? "none" : "block";
nodes.down.style.display = (end == context.items.length) ? "none" : "block"; nodes.down.style.display = (end == context.items.length) ? "none" : "block";
}); });
divNodes.noCompletions.style.display = (off > 0) ? "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(); autoSize();
return true; return true;

View File

@@ -48,6 +48,13 @@ const util = { //{{{
yield ary[i]; 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) uniq: function (ary, unsorted)
{ {
let ret = []; let ret = [];