diff --git a/content/completion.js b/content/completion.js index bc97cec1..7e6c118c 100644 --- a/content/completion.js +++ b/content/completion.js @@ -397,8 +397,6 @@ function Completion() //{{{ if (key in cache) return cache[key]; - // Can't use the cache. Build a member list. - let compl = []; // Things we can dereference if (["object", "string", "function"].indexOf(typeof obj) == -1) return []; @@ -414,12 +412,20 @@ function Completion() //{{{ obj = obj.wrappedJSObject; // v[0] in orig and orig[v[0]] catch different cases. XPCOM // 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, // return that, too. if (orig.wrappedJSObject) - compl.push([["wrappedJSObject", obj]]); - compl = util.Array.flatten(compl); + compl.push(["wrappedJSObject", obj]); + // 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; } @@ -428,7 +434,6 @@ function Completion() //{{{ context.title = [name]; context.anchored = anchored; 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. key = util.escapeString(key.substr(offset), ""); @@ -607,6 +612,14 @@ function Completion() //{{{ this.context = context; 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; try { diff --git a/content/template.js b/content/template.js index 222fa113..b8c28499 100644 --- a/content/template.js +++ b/content/template.js @@ -56,7 +56,8 @@ const template = { if (class) { - var [text, desc] = item; + var text = item[0] || ""; + var desc = item[1] || ""; } else { @@ -65,8 +66,8 @@ const template = { } return