diff --git a/content/completion.js b/content/completion.js index d62e1321..68cca9dd 100644 --- a/content/completion.js +++ b/content/completion.js @@ -27,6 +27,7 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // An eval with a cleaner lexical scope. +// TODO: that shows up in ":echo modules", can we move it "inside" the Completion class? --mst const EVAL_TMP = "__liberator_eval_tmp"; function __eval(__liberator_eval_arg, __liberator_eval_tmp) { @@ -201,6 +202,7 @@ function Completion() //{{{ if (key in cache) return cache[key]; + try { return cache[key] = __eval(arg, tmp); @@ -675,6 +677,13 @@ function Completion() //{{{ return []; }, + // cancel any ongoing search + cancel: function() + { + if (completionService) + completionService.stopSearch(); + }, + // discard all entries in the 'urls' array, which don't match 'filter // urls must be of type [["url", "title"], [...]] or optionally // [["url", "title", keyword, [tags]], [...]] @@ -1187,6 +1196,7 @@ function Completion() //{{{ else if (c == "l" && completionService) // add completions like Firefox's smart location bar { completionService.stopSearch(); + //dump("searching for " + filter + "\n"); completionService.startSearch(filter, "", historyResult, { onSearchResult: function onSearchResult(search, result) { historyResult = result; diff --git a/content/ui.js b/content/ui.js index 8e32b27b..07907bd9 100644 --- a/content/ui.js +++ b/content/ui.js @@ -153,6 +153,7 @@ function CommandLine() //{{{ var promptCompleter = null; liberator.registerCallback("change", modes.EX, function (command) { + completion.cancel(); // cancel any previous completion function if (options.get("wildoptions").has("auto")) autocompleteTimer.tell(command); else diff --git a/content/util.js b/content/util.js index da580861..f4770baa 100644 --- a/content/util.js +++ b/content/util.js @@ -76,6 +76,7 @@ const util = { //{{{ } }, + // TODO: class could have better variable names/documentation Timer: function Timer(minInterval, maxInterval, callback) { let timer = Components.classes["@mozilla.org/timer;1"] @@ -88,6 +89,7 @@ const util = { //{{{ this.latest = 0; /* minInterval is the time between the completion of the command and the next firing. */ this.doneAt = Date.now() + minInterval; + try { callback(this.arg); @@ -110,9 +112,10 @@ const util = { //{{{ if (now > this.doneAt && this.doneAt > -1) timeout = 0; else if (this.latest) - timeout = Math.min(minInterval, this.latest - now); + timeout = minInterval; else this.latest = now + maxInterval; + timer.initWithCallback(this, Math.max(timeout, 0), timer.TYPE_ONE_SHOT); this.doneAt = -1; };