1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 17:42:27 +01:00

Better JS completion sorting

This commit is contained in:
Kris Maglione
2008-11-25 08:12:41 +00:00
parent 9e142cd761
commit 18f2fc464c
2 changed files with 23 additions and 9 deletions

View File

@@ -397,8 +397,6 @@ function Completion() //{{{
if (key in cache) if (key in cache)
return cache[key]; return cache[key];
// Can't use the cache. Build a member list.
let compl = [];
// Things we can dereference // Things we can dereference
if (["object", "string", "function"].indexOf(typeof obj) == -1) if (["object", "string", "function"].indexOf(typeof obj) == -1)
return []; return [];
@@ -414,12 +412,20 @@ function Completion() //{{{
obj = obj.wrappedJSObject; obj = obj.wrappedJSObject;
// v[0] in orig and orig[v[0]] catch different cases. XPCOM // v[0] in orig and orig[v[0]] catch different cases. XPCOM
// objects are problematic, to say the least. // objects are problematic, to say the least.
compl.push([v for (v in this.iter(obj)) if (v[0] in orig || orig[v[0]] !== undefined)]) compl = [v for (v in this.iter(obj)) if (v[0] in orig || orig[v[0]] !== undefined)];
// And if wrappedJSObject happens to be available, // And if wrappedJSObject happens to be available,
// return that, too. // return that, too.
if (orig.wrappedJSObject) if (orig.wrappedJSObject)
compl.push([["wrappedJSObject", obj]]); compl.push(["wrappedJSObject", obj]);
compl = util.Array.flatten(compl); // Parse keys for sorting
compl.forEach(function (item) {
key = item[0];
if (!isNaN(key))
key = parseInt(key);
else if (/^[A-Z_]+$/.test(key))
key = "";
item.key = key;
});
return cache[key] = compl; return cache[key] = compl;
} }
@@ -428,7 +434,6 @@ function Completion() //{{{
context.title = [name]; context.title = [name];
context.anchored = anchored; context.anchored = anchored;
context.filter = key; context.filter = key;
context.process = [null, function highlight(item, v) template.highlight(v, true)];
if (last != undefined) // Escaping the key (without adding quotes), so it matches the escaped completions. if (last != undefined) // Escaping the key (without adding quotes), so it matches the escaped completions.
key = util.escapeString(key.substr(offset), ""); key = util.escapeString(key.substr(offset), "");
@@ -607,6 +612,14 @@ function Completion() //{{{
this.context = context; this.context = context;
let string = context.filter; let string = context.filter;
context.process = [null, function highlight(item, v) template.highlight(v, true)];
context.compare = function ({item: {key: a}}, {item: {key: b}})
{
if (!isNaN(a) && !isNaN(b))
return a - b;
return String.localeCompare(a, b);
}
let self = this; let self = this;
try try
{ {

View File

@@ -56,7 +56,8 @@ const template = {
if (class) if (class)
{ {
var [text, desc] = item; var text = item[0] || "";
var desc = item[1] || "";
} }
else else
{ {
@@ -65,8 +66,8 @@ const template = {
} }
return <ul class={class || "hl-CompItem"}> return <ul class={class || "hl-CompItem"}>
<li class="hl-CompResult">{text || ""}</li> <li class="hl-CompResult">{text}</li>
<li class="hl-CompDesc">{desc || ""}</li> <li class="hl-CompDesc">{desc}</li>
</ul>; </ul>;
}, },