From cebf7c539798a08fd258c55098e8d65949915fcb Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 3 Oct 2011 15:50:08 -0400 Subject: [PATCH] Fix processing of fake input events in the command line. --- common/content/commandline.js | 157 ++++++++++++++++++---------------- common/modules/template.jsm | 2 + 2 files changed, 86 insertions(+), 73 deletions(-) diff --git a/common/content/commandline.js b/common/content/commandline.js index 2a6dcc01..6f1e0e5a 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -379,7 +379,6 @@ var CommandMode = Class("CommandMode", { if (waiting) this.completions.onComplete = bind("onSubmit", this); - this.resetCompletions(); commandline.hideCompletions(); modes.delay(function () { @@ -395,6 +394,7 @@ var CommandMode = Class("CommandMode", { events: { input: function CM_onInput(event) { + util.dumpStack(); if (this.completions) { this.resetCompletions(); @@ -428,7 +428,7 @@ var CommandMode = Class("CommandMode", { resetCompletions: function CM_resetCompletions() { if (this.completions) - this.completions.quit(); + this.completions.clear(); if (this.history) this.history.reset(); }, @@ -1040,8 +1040,10 @@ var CommandLine = Module("commandline", { this.input = input; this.session = session; this.selected = null; + this.wildmode = options.get("wildmode"); this.wildtypes = this.wildmode.value; + this.itemList = commandline.completionList; this.itemList.open(this.context); @@ -1055,6 +1057,7 @@ var CommandLine = Module("commandline", { this.complete(true, false); } }, this); + this.tabTimer = Timer(0, 0, function tabTell(event) { let tabCount = this.tabCount; this.tabCount = 0; @@ -1064,23 +1067,6 @@ var CommandLine = Module("commandline", { tabCount: 0, - cleanup: function () { - dactyl.unregisterObserver("events.doneFeeding", this.closure.onDoneFeeding); - this.previewClear(); - this.tabTimer.reset(); - this.autocompleteTimer.reset(); - this.itemList.visible = false; - this.input.dactylKeyPress = undefined; - this.hasQuit = true; - }, - - quit: function quit() { - if (!this.onComplete) - this.context.cancelAll(); - this.wildIndex = -1; - this.previewClear(); - }, - ignoredCount: 0, onDoneFeeding: function onDoneFeeding() { if (this.ignoredCount) @@ -1144,17 +1130,96 @@ var CommandLine = Module("commandline", { complete: function complete(show, tabPressed) { this.session.ignoredCount = 0; + this.context.reset(); this.context.tabPressed = tabPressed; + this.session.complete(this.context); if (!this.session.active) return; + this.context.updateAsync = true; this.reset(show, tabPressed); this.wildIndex = 0; this._caret = this.caret; }, + cleanup: function () { + dactyl.unregisterObserver("events.doneFeeding", this.closure.onDoneFeeding); + this.previewClear(); + + this.tabTimer.reset(); + this.autocompleteTimer.reset(); + if (!this.onComplete) + this.context.cancelAll(); + + this.itemList.visible = false; + this.input.dactylKeyPress = undefined; + this.hasQuit = true; + }, + + saveInput: function saveInput() { + this.prefix = this.context.value.substring(0, this.start); + this.value = this.context.value.substring(this.start, this.caret); + this.suffix = this.context.value.substring(this.caret); + }, + + clear: function clear() { + this.context.cancelAll(); + this.wildIndex = -1; + this.previewClear(); + }, + + reset: function reset(show) { + this.waiting = null; + this.wildIndex = -1; + + this.saveInput(); + + if (show) { + this.itemList.update(); + if (this.haveType("list")) + this.itemList.visible = true; + this.selected = null; + this.wildIndex = 0; + } + + this.preview(); + }, + + asyncUpdate: function asyncUpdate(context) { + if (this.hasQuit) { + let item = this.getItem(this.waiting); + if (item && this.waiting && this.onComplete) { + this.onComplete(this.prefix + item.result + this.suffix); + this.waiting = null; + this.context.cancelAll(); + } + return; + } + + let value = this.editor.selection.focusNode.textContent; + this.saveInput(); + + this.itemList.updateContext(context); + + if (this.waiting && this.waiting[0] == context) + this.select(this.waiting); + else if (!this.waiting) { + let group = this.itemList.selectedGroup; + if (group && group.context == context && this.completion) { + this.selected = null; + if (group.selectedIdx != null) + this.selected = [group.context, group.selectedIdx]; + + this.completion = this.selected ? this.getItem().result + : this.value; + } + + this.preview(); + } + }, + haveType: function haveType(type) this.wildmode.checkHas(this.wildtype, type == "first" ? "" : type), @@ -1236,60 +1301,6 @@ var CommandLine = Module("commandline", { delete this.removeSubstring; }, - reset: function reset(show) { - this.waiting = null; - this.wildIndex = -1; - - this.prefix = this.context.value.substring(0, this.start); - this.value = this.context.value.substring(this.start, this.caret); - this.suffix = this.context.value.substring(this.caret); - - if (show) { - this.itemList.update(); - if (this.haveType("list")) - this.itemList.visible = true; - this.selected = null; - this.wildIndex = 0; - } - - this.preview(); - }, - - asyncUpdate: function asyncUpdate(context) { - if (this.hasQuit) { - let item = this.getItem(this.waiting); - if (item && this.waiting && this.onComplete) { - this.onComplete(this.prefix + item.result + this.suffix); - this.waiting = null; - this.context.cancelAll(); - } - return; - } - - let value = this.editor.selection.focusNode.textContent; - this.prefix = value.substring(0, this.start); - this.value = value.substring(this.start, this.caret); - this.suffix = value.substring(this.caret); - - this.itemList.updateContext(context); - - if (this.waiting && this.waiting[0] == context) - this.select(this.waiting); - else if (!this.waiting) { - let group = this.itemList.selectedGroup; - if (group && group.context == context && this.completion) { - this.selected = null; - if (group.selectedIdx != null) - this.selected = [group.context, group.selectedIdx]; - - this.completion = this.selected ? this.getItem().result - : this.value; - } - - this.preview(); - } - }, - select: function select(idx, count, fromTab) { count = count || 1; diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 27160290..b8aff65f 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -153,6 +153,8 @@ var Template = Module("Template", { let obj = params.eventTarget; let events = obj[this.getAttribute("events") || "events"]; + if (Set.has(events, "input")) + events["dactyl-input"] = events["input"]; for (let [event, handler] in Iterator(events)) node.addEventListener(event, obj.closure(handler), false);