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

Fix JS completion sorting bug. Remove some commented code.

This commit is contained in:
Kris Maglione
2009-08-03 17:33:31 -04:00
parent b946a5796a
commit 0b60f3ebcc
2 changed files with 10 additions and 24 deletions

View File

@@ -373,37 +373,20 @@ CompletionContext.prototype = {
{ {
this.hasItems = true; this.hasItems = true;
this._generate = arg; this._generate = arg;
//**/ liberator.dump(this.name + ": set generate()");
if (this.background && this.regenerate) if (this.background && this.regenerate)
{ {
//**/ this.__i = (this.__i || 0) + 1;
//**/ let self = this;
//**/ function dump(msg) liberator.callInMainThread(function () liberator.dump(self.name + ":" + self.__i + ": " + msg));
//**/ dump("set generate() regenerating");
let lock = {}; let lock = {};
this.cache.backgroundLock = lock; this.cache.backgroundLock = lock;
this.incomplete = true; this.incomplete = true;
let thread = this.getCache("backgroundThread", liberator.newThread); let thread = this.getCache("backgroundThread", liberator.newThread);
//**/ dump(thread);
liberator.callAsync(thread, this, function () { liberator.callAsync(thread, this, function () {
//**/ dump("In async");
if (this.cache.backgroundLock != lock) if (this.cache.backgroundLock != lock)
{
//**/ dump("Lock !ok");
return; return;
}
let items = this.generate(); let items = this.generate();
//**/ dump("Generated");
if (this.cache.backgroundLock != lock) if (this.cache.backgroundLock != lock)
{
//**/ dump("Lock !ok");
return; return;
}
this.incomplete = false; this.incomplete = false;
//**/ dump("completions=");
this.completions = items; this.completions = items;
//**/ dump("completions==");
}); });
} }
}, },
@@ -1124,11 +1107,12 @@ function Completion() //{{{
// Constants are unsorted, and appear before other non-null strings. // Constants are unsorted, and appear before other non-null strings.
// Other strings are sorted in the default manner. // Other strings are sorted in the default manner.
let compare = context.compare; let compare = context.compare;
function isnan(item) item != '' && isNaN(item);
context.compare = function (a, b) context.compare = function (a, b)
{ {
if (!isNaN(a.item.key) && !isNaN(b.item.key)) if (!isnan(a.item.key) && !isnan(b.item.key))
return a.item.key - b.item.key; return a.item.key - b.item.key;
return isNaN(b.item.key) - isNaN(a.item.key) || compare(a.item.key, b.item.key); return isnan(b.item.key) - isnan(a.item.key) || compare(a, b);
} }
if (!context.anchored) // We've already listed anchored matches, so don't list them again here. if (!context.anchored) // We've already listed anchored matches, so don't list them again here.
context.filters.push(function (item) util.compareIgnoreCase(item.text.substr(0, this.filter.length), this.filter)); context.filters.push(function (item) util.compareIgnoreCase(item.text.substr(0, this.filter.length), this.filter));

View File

@@ -1743,6 +1743,8 @@ function ItemList(id) //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const WAITING_MESSAGE = "Generating results...";
var completionElements = []; var completionElements = [];
var iframe = document.getElementById(id); var iframe = document.getElementById(id);
@@ -1817,7 +1819,7 @@ function ItemList(id) //{{{
<div key="message" highlight="CompMsg"/> <div key="message" highlight="CompMsg"/>
<div key="up" highlight="CompLess"/> <div key="up" highlight="CompLess"/>
<div key="items" highlight="Completions"/> <div key="items" highlight="Completions"/>
<div key="waiting" highlight="CompMsg">Waiting...</div> <div key="waiting" highlight="CompMsg">{WAITING_MESSAGE}</div>
<div key="down" highlight="CompMore"/> <div key="down" highlight="CompMore"/>
</div>, context.cache.nodes); </div>, context.cache.nodes);
divNodes.completions.appendChild(context.cache.nodes.root); divNodes.completions.appendChild(context.cache.nodes.root);
@@ -1848,13 +1850,13 @@ function ItemList(id) //{{{
function getRows(context) function getRows(context)
{ {
function fix(n) util.Math.constrain(n, 0, len); function fix(n) util.Math.constrain(n, 0, len);
end -= !!context.message + context.incomplete;
let len = context.items.length; let len = context.items.length;
let start = off; let start = off;
end -= !!context.message + context.incomplete;
off += len; off += len;
let res = [fix(offset - start), fix(end - start)];
res[2] = (context.incomplete && res[1] >= offset && off - 1 < end); let s = fix(offset - start), e = fix(end - start);
return res; return [s, e, context.incomplete && e >= offset && off - 1 < end];
} }
items.contextList.forEach(function fill_eachContext(context) { items.contextList.forEach(function fill_eachContext(context) {