diff --git a/common/content/hints.js b/common/content/hints.js index c1f18eb1..ddf90824 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -598,8 +598,17 @@ function Hints() //{{{ mappings.add(myModes, [";"], "Start an extended hint mode", - function (arg) { hints.show(arg); }, - { flags: Mappings.flags.ARGUMENT }); + function (arg) { + commandline.input(";", function (arg) { setTimeout(function () hints.show(arg), 0) }, + { + promptHighlight: "Normal", + completer: function (context) { + context.completions = [[k, v.prompt] for ([k, v] in Iterator(hintModes))]; + }, + onChange: function () { modes.pop() } + }); + }); + //{ flags: Mappings.flags.ARGUMENT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// PUBLIC SECTION ////////////////////////////////////////// @@ -620,7 +629,7 @@ function Hints() //{{{ liberator.beep(); return; } - commandline.input(hintMode.prompt + ":", null, { onChange: onInput }); + commandline.input(hintMode.prompt + ": ", null, { onChange: onInput }); modes.extended = modes.HINTS; submode = minor; diff --git a/common/content/liberator.js b/common/content/liberator.js index 9f6472d8..4e564404 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1026,7 +1026,7 @@ const liberator = (function () //{{{ if (urls.length > 20 && !force) { - commandline.input("This will open " + urls.length + " new tabs. Would you like to continue? (yes/[no])", + commandline.input("This will open " + urls.length + " new tabs. Would you like to continue? (yes/[no]) ", function (resp) { if (resp && resp.match(/^y(es)?$/i)) liberator.open(urls, where, true); diff --git a/common/content/modes.js b/common/content/modes.js index 0f94f589..ced63386 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -152,6 +152,8 @@ const modes = (function () //{{{ mainModes.push(this[name]); }, + getMode: function (name) modeMap[name], + // show the current mode string in the command line show: function () { @@ -180,12 +182,12 @@ const modes = (function () //{{{ // if a main mode is set, the extended is always cleared if (typeof mainMode === "number") { + if (!silent && mainMode != main) + handleModeChange(main, mainMode); + main = mainMode; if (!extendedMode) extended = modes.NONE; - - if (!silent && mainMode != main) - handleModeChange(main, mainMode); } if (typeof extendedMode === "number") extended = extendedMode; diff --git a/common/content/ui.js b/common/content/ui.js index b76fd8a8..68f9fc0a 100644 --- a/common/content/ui.js +++ b/common/content/ui.js @@ -375,22 +375,21 @@ function CommandLine() //{{{ liberator.registerCallback("cancel", modes.PROMPT, closePrompt); liberator.registerCallback("submit", modes.PROMPT, closePrompt); liberator.registerCallback("change", modes.PROMPT, function (str) { + liberator.triggerCallback("change", modes.EX, str); if (promptChangeCallback) - return promptChangeCallback(str); + return promptChangeCallback.call(commandline, str); }); liberator.registerCallback("complete", modes.PROMPT, function (context) { if (promptCompleter) - promptCompleter(context); + context.fork("input", 0, commandline, promptCompleter); }); function closePrompt(value) { let callback = promptSubmitCallback; promptSubmitCallback = null; - currentExtendedMode = null; - commandline.clear(); if (callback) - callback(value); + callback.call(commandline, value == null ? commandline.getCommand() : value); } /////////////////////////////////////////////////////////////////////////////}}} @@ -845,9 +844,14 @@ function CommandLine() //{{{ // normally used when pressing esc, does not execute a command close: function close() { - let res = liberator.triggerCallback("cancel", currentExtendedMode); + let mode = currentExtendedMode; + currentExtendedMode = null; + liberator.triggerCallback("cancel", mode); + inputHistory.add(this.getCommand()); statusline.updateProgress(""); // we may have a "match x of y" visible + liberator.focusContent(false); + this.clear(); }, @@ -911,11 +915,15 @@ function CommandLine() //{{{ promptSubmitCallback = callback; promptChangeCallback = extra.onChange; promptCompleter = extra.completer; + modes.push(modes.COMMAND_LINE, modes.PROMPT); currentExtendedMode = modes.PROMPT; - setPrompt(prompt + " ", this.HL_QUESTION); + + setPrompt(prompt, extra.promptHighlight || this.HL_QUESTION); setCommand(extra.default || ""); commandWidget.focus(); + + completions = new Completions(CompletionContext(commandWidget.inputField.editor)); }, // reads a multi line input and returns the string once the last line matches @@ -938,7 +946,8 @@ function CommandLine() //{{{ onEvent: function onEvent(event) { - completions.previewClear(); + if (completions) + completions.previewClear(); let command = this.getCommand(); if (event.type == "blur") @@ -979,14 +988,10 @@ function CommandLine() //{{{ // FIXME: should trigger "cancel" event if (events.isAcceptKey(key)) { - let mode = currentExtendedMode; // save it here, as setMode() resets it + let mode = currentExtendedMode; // save it here, as modes.pop() resets it currentExtendedMode = null; /* Don't let modes.pop trigger "cancel" */ - inputHistory.add(command); - modes.pop(!commandline.silent); - this.resetCompletions(); - completionList.hide(); - liberator.focusContent(false); - statusline.updateProgress(""); // we may have a "match x of y" visible + modes.pop(); + return liberator.triggerCallback("submit", mode, command); } // user pressed UP or DOWN arrow to cycle history completion