mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 09:08:37 +01:00
Fix JS completion sorting bug. Remove some commented code.
This commit is contained in:
@@ -373,37 +373,20 @@ CompletionContext.prototype = {
|
||||
{
|
||||
this.hasItems = true;
|
||||
this._generate = arg;
|
||||
//**/ liberator.dump(this.name + ": set generate()");
|
||||
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 = {};
|
||||
this.cache.backgroundLock = lock;
|
||||
this.incomplete = true;
|
||||
let thread = this.getCache("backgroundThread", liberator.newThread);
|
||||
//**/ dump(thread);
|
||||
liberator.callAsync(thread, this, function () {
|
||||
//**/ dump("In async");
|
||||
if (this.cache.backgroundLock != lock)
|
||||
{
|
||||
//**/ dump("Lock !ok");
|
||||
return;
|
||||
}
|
||||
let items = this.generate();
|
||||
//**/ dump("Generated");
|
||||
if (this.cache.backgroundLock != lock)
|
||||
{
|
||||
//**/ dump("Lock !ok");
|
||||
return;
|
||||
}
|
||||
this.incomplete = false;
|
||||
//**/ dump("completions=");
|
||||
this.completions = items;
|
||||
//**/ dump("completions==");
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -1124,11 +1107,12 @@ function Completion() //{{{
|
||||
// Constants are unsorted, and appear before other non-null strings.
|
||||
// Other strings are sorted in the default manner.
|
||||
let compare = context.compare;
|
||||
function isnan(item) item != '' && isNaN(item);
|
||||
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 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.
|
||||
context.filters.push(function (item) util.compareIgnoreCase(item.text.substr(0, this.filter.length), this.filter));
|
||||
|
||||
@@ -1743,6 +1743,8 @@ function ItemList(id) //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
const WAITING_MESSAGE = "Generating results...";
|
||||
|
||||
var completionElements = [];
|
||||
|
||||
var iframe = document.getElementById(id);
|
||||
@@ -1817,7 +1819,7 @@ function ItemList(id) //{{{
|
||||
<div key="message" highlight="CompMsg"/>
|
||||
<div key="up" highlight="CompLess"/>
|
||||
<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>, context.cache.nodes);
|
||||
divNodes.completions.appendChild(context.cache.nodes.root);
|
||||
@@ -1848,13 +1850,13 @@ function ItemList(id) //{{{
|
||||
function getRows(context)
|
||||
{
|
||||
function fix(n) util.Math.constrain(n, 0, len);
|
||||
end -= !!context.message + context.incomplete;
|
||||
let len = context.items.length;
|
||||
let start = off;
|
||||
end -= !!context.message + context.incomplete;
|
||||
off += len;
|
||||
let res = [fix(offset - start), fix(end - start)];
|
||||
res[2] = (context.incomplete && res[1] >= offset && off - 1 < end);
|
||||
return res;
|
||||
|
||||
let s = fix(offset - start), e = fix(end - start);
|
||||
return [s, e, context.incomplete && e >= offset && off - 1 < end];
|
||||
}
|
||||
|
||||
items.contextList.forEach(function fill_eachContext(context) {
|
||||
|
||||
Reference in New Issue
Block a user