mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 11:58:00 +01:00
made autocompletions not hang the GUI for quick input
This commit is contained in:
@@ -27,6 +27,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
|||||||
}}} ***** END LICENSE BLOCK *****/
|
}}} ***** END LICENSE BLOCK *****/
|
||||||
|
|
||||||
// An eval with a cleaner lexical scope.
|
// 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";
|
const EVAL_TMP = "__liberator_eval_tmp";
|
||||||
function __eval(__liberator_eval_arg, __liberator_eval_tmp)
|
function __eval(__liberator_eval_arg, __liberator_eval_tmp)
|
||||||
{
|
{
|
||||||
@@ -201,6 +202,7 @@ function Completion() //{{{
|
|||||||
|
|
||||||
if (key in cache)
|
if (key in cache)
|
||||||
return cache[key];
|
return cache[key];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return cache[key] = __eval(arg, tmp);
|
return cache[key] = __eval(arg, tmp);
|
||||||
@@ -675,6 +677,13 @@ function Completion() //{{{
|
|||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// cancel any ongoing search
|
||||||
|
cancel: function()
|
||||||
|
{
|
||||||
|
if (completionService)
|
||||||
|
completionService.stopSearch();
|
||||||
|
},
|
||||||
|
|
||||||
// discard all entries in the 'urls' array, which don't match 'filter
|
// discard all entries in the 'urls' array, which don't match 'filter
|
||||||
// urls must be of type [["url", "title"], [...]] or optionally
|
// urls must be of type [["url", "title"], [...]] or optionally
|
||||||
// [["url", "title", keyword, [tags]], [...]]
|
// [["url", "title", keyword, [tags]], [...]]
|
||||||
@@ -1187,6 +1196,7 @@ function Completion() //{{{
|
|||||||
else if (c == "l" && completionService) // add completions like Firefox's smart location bar
|
else if (c == "l" && completionService) // add completions like Firefox's smart location bar
|
||||||
{
|
{
|
||||||
completionService.stopSearch();
|
completionService.stopSearch();
|
||||||
|
//dump("searching for " + filter + "\n");
|
||||||
completionService.startSearch(filter, "", historyResult, {
|
completionService.startSearch(filter, "", historyResult, {
|
||||||
onSearchResult: function onSearchResult(search, result) {
|
onSearchResult: function onSearchResult(search, result) {
|
||||||
historyResult = result;
|
historyResult = result;
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ function CommandLine() //{{{
|
|||||||
var promptCompleter = null;
|
var promptCompleter = null;
|
||||||
|
|
||||||
liberator.registerCallback("change", modes.EX, function (command) {
|
liberator.registerCallback("change", modes.EX, function (command) {
|
||||||
|
completion.cancel(); // cancel any previous completion function
|
||||||
if (options.get("wildoptions").has("auto"))
|
if (options.get("wildoptions").has("auto"))
|
||||||
autocompleteTimer.tell(command);
|
autocompleteTimer.tell(command);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ const util = { //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// TODO: class could have better variable names/documentation
|
||||||
Timer: function Timer(minInterval, maxInterval, callback)
|
Timer: function Timer(minInterval, maxInterval, callback)
|
||||||
{
|
{
|
||||||
let timer = Components.classes["@mozilla.org/timer;1"]
|
let timer = Components.classes["@mozilla.org/timer;1"]
|
||||||
@@ -88,6 +89,7 @@ const util = { //{{{
|
|||||||
this.latest = 0;
|
this.latest = 0;
|
||||||
/* minInterval is the time between the completion of the command and the next firing. */
|
/* minInterval is the time between the completion of the command and the next firing. */
|
||||||
this.doneAt = Date.now() + minInterval;
|
this.doneAt = Date.now() + minInterval;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
callback(this.arg);
|
callback(this.arg);
|
||||||
@@ -110,9 +112,10 @@ const util = { //{{{
|
|||||||
if (now > this.doneAt && this.doneAt > -1)
|
if (now > this.doneAt && this.doneAt > -1)
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
else if (this.latest)
|
else if (this.latest)
|
||||||
timeout = Math.min(minInterval, this.latest - now);
|
timeout = minInterval;
|
||||||
else
|
else
|
||||||
this.latest = now + maxInterval;
|
this.latest = now + maxInterval;
|
||||||
|
|
||||||
timer.initWithCallback(this, Math.max(timeout, 0), timer.TYPE_ONE_SHOT);
|
timer.initWithCallback(this, Math.max(timeout, 0), timer.TYPE_ONE_SHOT);
|
||||||
this.doneAt = -1;
|
this.doneAt = -1;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user