mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 22:38:00 +01:00
Allow canceling of asynchronous completions. Some other small completion cleanups. NOTE to myself: The completion/commandline code is quite spaghetti code again, need to reduce unused functions, and reduce side effects inside functions like resetCompletions
This commit is contained in:
@@ -112,6 +112,12 @@ function CompletionContext(editor, name, offset) //{{{
|
|||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
this.compare = function (a, b) String.localeCompare(a.text, b.text);
|
this.compare = function (a, b) String.localeCompare(a.text, b.text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {function} This function is called when we close
|
||||||
|
* a completion window with Esc or Ctrl-c. Usually this callback
|
||||||
|
* is only needed for long, asynchronous completions
|
||||||
|
*/
|
||||||
|
this.cancelFunc = null;
|
||||||
/**
|
/**
|
||||||
* @property {function} The function used to filter the results.
|
* @property {function} The function used to filter the results.
|
||||||
* @default Selects all results which match every predicate in the
|
* @default Selects all results which match every predicate in the
|
||||||
@@ -151,7 +157,7 @@ function CompletionContext(editor, name, offset) //{{{
|
|||||||
* Names are assigned when a context is forked, with its specified
|
* Names are assigned when a context is forked, with its specified
|
||||||
* name appended, after a '/', to its parent's name.
|
* name appended, after a '/', to its parent's name.
|
||||||
*/
|
*/
|
||||||
this.contexts = { name: this };
|
this.contexts = { "/": this };
|
||||||
/**
|
/**
|
||||||
* @property {Object} A mapping of keys, for {@link #getKey}. Given
|
* @property {Object} A mapping of keys, for {@link #getKey}. Given
|
||||||
* { key: value }, getKey(item, key) will return values as such:
|
* { key: value }, getKey(item, key) will return values as such:
|
||||||
@@ -1549,13 +1555,15 @@ function Completion() //{{{
|
|||||||
location: function location(context)
|
location: function location(context)
|
||||||
{
|
{
|
||||||
if (!services.get("autoCompleteSearch"))
|
if (!services.get("autoCompleteSearch"))
|
||||||
return
|
return;
|
||||||
|
|
||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.title = ["Smart Completions"];
|
context.title = ["Smart Completions"];
|
||||||
context.keys.icon = 2;
|
context.keys.icon = 2;
|
||||||
context.incomplete = true;
|
context.incomplete = true;
|
||||||
context.hasItems = context.completions.length > 0; // XXX
|
context.hasItems = context.completions.length > 0; // XXX
|
||||||
context.filterFunc = null;
|
context.filterFunc = null;
|
||||||
|
context.cancelFunc = function () services.get("autoCompleteSearch").stopSearch();
|
||||||
context.compare = null;
|
context.compare = null;
|
||||||
let timer = new Timer(50, 100, function (result) {
|
let timer = new Timer(50, 100, function (result) {
|
||||||
context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING;
|
context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING;
|
||||||
|
|||||||
@@ -936,6 +936,7 @@ function CommandLine() //{{{
|
|||||||
if (history)
|
if (history)
|
||||||
history.save();
|
history.save();
|
||||||
|
|
||||||
|
this.resetCompletions(); // cancels any asynchronous completion still going on, must be before completions = null
|
||||||
completions = null;
|
completions = null;
|
||||||
history = null;
|
history = null;
|
||||||
|
|
||||||
@@ -1075,7 +1076,7 @@ function CommandLine() //{{{
|
|||||||
}
|
}
|
||||||
else if (event.type == "input")
|
else if (event.type == "input")
|
||||||
{
|
{
|
||||||
this.resetCompletions();
|
//this.resetCompletions(); -> already handled by "keypress" below (hopefully), so don't do it twice
|
||||||
liberator.triggerCallback("change", currentExtendedMode, command);
|
liberator.triggerCallback("change", currentExtendedMode, command);
|
||||||
}
|
}
|
||||||
else if (event.type == "keypress")
|
else if (event.type == "keypress")
|
||||||
@@ -1432,8 +1433,15 @@ function CommandLine() //{{{
|
|||||||
resetCompletions: function resetCompletions()
|
resetCompletions: function resetCompletions()
|
||||||
{
|
{
|
||||||
autocompleteTimer.reset();
|
autocompleteTimer.reset();
|
||||||
|
|
||||||
|
// liberator.dump("Resetting completions...");
|
||||||
if (completions)
|
if (completions)
|
||||||
{
|
{
|
||||||
|
// if any child context has a cancelFunc, call it
|
||||||
|
for (let [, context] in Iterator(completions.context.top.contexts))
|
||||||
|
if (context.cancelFunc)
|
||||||
|
context.cancelFunc();
|
||||||
|
|
||||||
completions.wildIndex = -1;
|
completions.wildIndex = -1;
|
||||||
completions.previewClear();
|
completions.previewClear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const Ci = Components.interfaces;
|
|||||||
const Cr = Components.results;
|
const Cr = Components.results;
|
||||||
const Cu = Components.utils;
|
const Cu = Components.utils;
|
||||||
|
|
||||||
|
// XXX: does not belong here
|
||||||
function Timer(minInterval, maxInterval, callback)
|
function Timer(minInterval, maxInterval, callback)
|
||||||
{
|
{
|
||||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ commands.addUserCommand(["regr[essions]"],
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
liberator.echomsg("Running test " + currentTest + " of " + totalTests + ": " + testDescription, 0);
|
commandline.echo("Running test " + currentTest + " of " + totalTests + ": " + testDescription, "Filter", commandline.APPEND_TO_MESSAGES);
|
||||||
resetEnvironment();
|
resetEnvironment();
|
||||||
if ("init" in test)
|
if ("init" in test)
|
||||||
test.init();
|
test.init();
|
||||||
@@ -206,7 +206,7 @@ commands.addUserCommand(["regr[essions]"],
|
|||||||
if (args.count >= 1 && currentTest != args.count)
|
if (args.count >= 1 && currentTest != args.count)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
liberator.echomsg("Running test " + currentTest + " of " + totalTests + ": " + util.clip(func.toString().replace(/[\s\n]+/gm, " "), 80));
|
commandline.echo("Running test " + currentTest + " of " + totalTests + ": " + util.clip(func.toString().replace(/[\s\n]+/gm, " "), 80), "Filter", commandline.APPEND_TO_MESSAGES);
|
||||||
resetEnvironment();
|
resetEnvironment();
|
||||||
|
|
||||||
if (!func())
|
if (!func())
|
||||||
|
|||||||
Reference in New Issue
Block a user