X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fcontent%2Fcommandline.js;fp=common%2Fcontent%2Fcommandline.js;h=cae99423a67e83c50f1051ea9312bacb30305850;hb=70740024f9c028c1fd63e1a1850ab062ff956054;hp=69e6a3cc24e6118d23725b31754ef6ff5a350b8f;hpb=718c614c183350706466e22939d0101ca4c87efe;p=dactyl.git diff --git a/common/content/commandline.js b/common/content/commandline.js index 69e6a3c..cae9942 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -152,6 +152,7 @@ var CommandWidgets = Class("CommandWidgets", { return this.commandbar; } }); + this.updateVisibility(); }, addElement: function addElement(obj) { const self = this; @@ -174,7 +175,7 @@ var CommandWidgets = Class("CommandWidgets", { if (obj.value != null) return [obj.value[0], obj.get ? obj.get.call(this, elem) : elem.value] - .concat(obj.value.slice(2)) + .concat(obj.value.slice(2)); return null; }, @@ -300,19 +301,21 @@ var CommandWidgets = Class("CommandWidgets", { }); var CommandMode = Class("CommandMode", { - init: function init() { + init: function CM_init() { this.keepCommand = userContext.hidden_option_command_afterimage; }, + get autocomplete() options["autocomplete"].length, + get command() this.widgets.command[1], set command(val) this.widgets.command = val, get prompt() this.widgets.prompt, set prompt(val) this.widgets.prompt = val, - open: function (command) { + open: function CM_open(command) { dactyl.assert(isinstance(this.mode, modes.COMMAND_LINE), - "Not opening command line in non-command-line mode."); + /*L*/"Not opening command line in non-command-line mode."); this.messageCount = commandline.messageCount; modes.push(this.mode, this.extendedMode, this.closure); @@ -340,7 +343,7 @@ var CommandMode = Class("CommandMode", { get widgets() commandline.widgets, - enter: function (stack) { + enter: function CM_enter(stack) { commandline.commandSession = this; if (stack.pop && commandline.command) { this.onChange(commandline.command); @@ -349,7 +352,7 @@ var CommandMode = Class("CommandMode", { } }, - leave: function (stack) { + leave: function CM_leave(stack) { if (!stack.push) { commandline.commandSession = null; this.input.dactylKeyPress = undefined; @@ -374,7 +377,7 @@ var CommandMode = Class("CommandMode", { }, events: { - input: function onInput(event) { + input: function CM_onInput(event) { if (this.completions) { this.resetCompletions(); @@ -382,7 +385,7 @@ var CommandMode = Class("CommandMode", { } this.onChange(commandline.command); }, - keyup: function onKeyUp(event) { + keyup: function CM_onKeyUp(event) { let key = events.toString(event); if (/-?Tab>$/.test(key) && this.completions) this.completions.tabTimer.flush(); @@ -391,23 +394,22 @@ var CommandMode = Class("CommandMode", { keepCommand: false, - onKeyPress: function onKeyPress(events) { + onKeyPress: function CM_onKeyPress(events) { if (this.completions) this.completions.previewClear(); return true; /* Pass event */ }, - onCancel: function (value) { - }, + onCancel: function (value) {}, - onChange: function (value) { - }, + onChange: function (value) {}, - onSubmit: function (value) { - }, + onHistory: function (value) {}, + + onSubmit: function (value) {}, - resetCompletions: function resetCompletions() { + resetCompletions: function CM_resetCompletions() { if (this.completions) { this.completions.context.cancelAll(); this.completions.wildIndex = -1; @@ -426,12 +428,12 @@ var CommandExMode = Class("CommandExMode", CommandMode, { prompt: ["Normal", ":"], - complete: function complete(context) { + complete: function CEM_complete(context) { context.fork("ex", 0, completion, "ex"); }, - onSubmit: function onSubmit(command) { - contexts.withContext({ file: "[Command Line]", line: 1 }, + onSubmit: function CEM_onSubmit(command) { + contexts.withContext({ file: /*L*/"[Command Line]", line: 1 }, function _onSubmit() { io.withSavedValues(["readHeredoc"], function _onSubmit() { this.readHeredoc = commandline.readHeredoc; @@ -449,7 +451,7 @@ var CommandPromptMode = Class("CommandPromptMode", CommandMode, { init.supercall(this); }, - complete: function (context) { + complete: function CPM_complete(context) { if (this.completer) context.forkapply("prompt", 0, this, "completer", Array.slice(arguments, 1)); }, @@ -586,6 +588,9 @@ var CommandLine = Module("commandline", { get completionList() { let node = this.widgets.active.commandline; + if (this.commandSession && this.commandSession.completionList) + node = document.getElementById(this.commandSession.completionList); + if (!node.completionList) { let elem = document.getElementById("dactyl-completions-" + node.id); util.waitFor(bind(this.widgets._ready, null, elem)); @@ -648,11 +653,11 @@ var CommandLine = Module("commandline", { * @param {XML} xml The output as an E4X XML object. */ commandOutput: function commandOutput(xml) { - XML.ignoreWhitespace = false; - XML.prettyPrinting = false; + XML.ignoreWhitespace = XML.prettyPrinting = false; if (this.command) - this.echo(<>:{this.command}, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE); - this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE); + this.echo(<>
:{this.command}
{xml}, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE); + else + this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE); this.command = null; }, @@ -722,6 +727,9 @@ var CommandLine = Module("commandline", { if (flags & this.APPEND_TO_MESSAGES) { let message = isObject(data) ? data : { message: data }; + + // Make sure the memoized message property is an instance property. + message.message; this._messageHistory.add(update({ highlight: highlightGroup }, message)); data = message.message; } @@ -737,7 +745,7 @@ var CommandLine = Module("commandline", { let single = flags & (this.FORCE_SINGLELINE | this.DISALLOW_MULTILINE); let action = this._echoLine; - if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isString(data)) && !(flags & this.FORCE_SINGLELINE)) + if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isinstance(data, [_, "String"])) && !(flags & this.FORCE_SINGLELINE)) action = mow.closure.echo; if (single) @@ -803,12 +811,20 @@ var CommandLine = Module("commandline", { // FIXME: Buggy, especially when pasting. inputMultiline: function inputMultiline(end, callback) { let cmd = this.command; + let self = { + end: "\n" + end + "\n", + callback: callback + }; + modes.push(modes.INPUT_MULTILINE, null, { - mappingSelf: { - end: "\n" + end + "\n", - callback: callback - } + holdFocus: true, + leave: function leave() { + if (!self.done) + self.callback(null); + }, + mappingSelf: self }); + if (cmd != false) this._echoLine(cmd, this.HL_NORMAL); @@ -838,7 +854,7 @@ var CommandLine = Module("commandline", { event.target.blur(); dactyl.beep(); } - }, + } } ), @@ -940,6 +956,7 @@ var CommandLine = Module("commandline", { if (this.completions) this.completions.previewClear(); this.input.value = val; + this.session.onHistory(val); }, /** @@ -1014,9 +1031,9 @@ var CommandLine = Module("commandline", { dactyl.registerObserver("events.doneFeeding", this.closure.onDoneFeeding, true); this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) { - if (events.feedingKeys) + if (events.feedingKeys && !tabPressed) this.ignoredCount++; - if (options["autocomplete"].length) { + else if (this.session.autocomplete) { this.itemList.visible = true; this.complete(true, false); } @@ -1086,6 +1103,7 @@ var CommandLine = Module("commandline", { get wildtype() this.wildtypes[this.wildIndex] || "", complete: function complete(show, tabPressed) { + this.session.ignoredCount = 0; this.context.reset(); this.context.tabPressed = tabPressed; this.session.complete(this.context); @@ -1230,7 +1248,7 @@ var CommandLine = Module("commandline", { for (let [, context] in Iterator(list)) { let done = function done() !(idx >= n + context.items.length || idx == -2 && !context.items.length); - util.waitFor(function () !context.incomplete || done()) + util.waitFor(function () !context.incomplete || done()); if (done()) break; @@ -1259,6 +1277,7 @@ var CommandLine = Module("commandline", { tab: function tab(reverse, wildmode) { this.autocompleteTimer.flush(); + this.ignoredCount = 0; if (this._caret != this.caret) this.reset(); @@ -1301,7 +1320,7 @@ var CommandLine = Module("commandline", { if (this.selected == null) statusline.progress = ""; else - statusline.progress = "match " + (this.selected + 1) + " of " + this.items.length; + statusline.progress = _("completion.matchIndex", this.selected + 1, this.items.length); } if (this.items.length == 0) @@ -1415,7 +1434,7 @@ var CommandLine = Module("commandline", { mappings: function init_mappings() { mappings.add([modes.COMMAND], - [":"], "Enter command-line mode", + [":"], "Enter Command Line mode", function () { CommandExMode().open(""); }); mappings.add([modes.INPUT_MULTILINE], @@ -1427,6 +1446,7 @@ var CommandLine = Module("commandline", { let index = text.indexOf(self.end); if (index >= 0) { + self.done = true; text = text.substring(1, index); modes.pop(); @@ -1614,7 +1634,7 @@ var ItemList = Class("ItemList", { _init: function _init() { this._div = this._dom(
-
No Completions
+
{_("completion.noCompletions")}
{ @@ -1812,7 +1832,7 @@ var ItemList = Class("ItemList", { onKeyPress: function onKeyPress(event) false }, { - WAITING_MESSAGE: "Generating results..." + WAITING_MESSAGE: _("completion.generating") }); // vim: set fdm=marker sw=4 ts=4 et: