From 798f26c7464a7071410a3c14b1e414ac53876cd6 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 10 Oct 2011 02:48:05 -0400 Subject: [PATCH] Hint processing mapping state magic stuff. --- common/content/hints.js | 50 ++++++++++++++++++++------------------ common/content/mappings.js | 2 +- common/content/mow.js | 5 ++++ common/modules/buffer.jsm | 2 +- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/common/content/hints.js b/common/content/hints.js index 2f4f7230..d5f6ef55 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -17,8 +17,6 @@ var HintSession = Class("HintSession", CommandMode, { opts = opts || {}; - this.forceOpen = opts.forceOpen || dactyl.forceOpen; - if (!opts.window) opts.window = modes.getStack(0).params.window; @@ -36,6 +34,7 @@ var HintSession = Class("HintSession", CommandMode, { this.usedTabKey = false; this.validHints = []; // store the indices of the "hints" array with valid elements + mappings.pushCommand(); this.open(); this.top = opts.window || content; @@ -99,6 +98,8 @@ var HintSession = Class("HintSession", CommandMode, { leave.superapply(this, arguments); if (!stack.push) { + mappings.popCommand(); + if (hints.hintSession == this) hints.hintSession = null; if (this.top) { @@ -500,18 +501,17 @@ var HintSession = Class("HintSession", CommandMode, { this.timeout(next, 50); }).call(this); + mappings.pushCommand(); if (!this.continue) { modes.pop(); if (timeout) modes.push(modes.IGNORE, modes.HINTS); } - dactyl.withSavedValues(["forceOpen"], function () { - dactyl.forceOpen = this.forceOpen; - dactyl.trapErrors("action", this.hintMode, - elem, elem.href || elem.src || "", - this.extendedhintCount, top); - }, this); + dactyl.trapErrors("action", this.hintMode, + elem, elem.href || elem.src || "", + this.extendedhintCount, top); + mappings.popCommand(); this.timeout(function () { if (modes.main == modes.IGNORE && !this.continue) @@ -757,8 +757,8 @@ var Hints = Module("hints", { this.addMode("S", "Add a search keyword", function (elem) bookmarks.addSearchKeyword(elem)); this.addMode("v", "View hint source", function (elem, loc) buffer.viewSource(loc, false)); this.addMode("V", "View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true)); - this.addMode("y", "Yank hint location", function (elem, loc) dactyl.clipboardWrite(loc, true)); - this.addMode("Y", "Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", true)); + this.addMode("y", "Yank hint location", function (elem, loc) editor.setRegister(null, loc, true)); + this.addMode("Y", "Yank hint description", function (elem) editor.setRegister(null, elem.textContent || "", true)); this.addMode("c", "Open context menu", function (elem) DOM(elem).contextmenu()); this.addMode("i", "Show image", function (elem) dactyl.open(elem.src)); this.addMode("I", "Show image in a new tab", function (elem) dactyl.open(elem.src, dactyl.NEW_TAB)); @@ -1036,18 +1036,19 @@ var Hints = Module("hints", { this._extendedhintCount = opts.count; opts = opts || {}; - if (!Set.has(opts, "forceOpen")) - opts.forceOpen = dactyl.forceOpen; - commandline.input(["Normal", mode], "", { + mappings.pushCommand(); + commandline.input(["Normal", mode], null, { autocomplete: false, completer: function (context) { context.compare = function () 0; context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))]; }, + onCancel: mappings.closure.popCommand, onSubmit: function (arg) { if (arg) hints.show(arg, opts); + mappings.popCommand(); }, onChange: function (arg) { if (Object.keys(hints.modes).some(function (m) m != arg && m.indexOf(arg) == 0)) @@ -1216,42 +1217,45 @@ var Hints = Module("hints", { }); }, mappings: function () { - var myModes = config.browserModes.concat(modes.OUTPUT_MULTILINE); - mappings.add(myModes, ["f"], + let bind = function bind(names, description, action, params) + mappings.add(config.browserModes, names, description, + action, params); + + bind(["f"], "Start Hints mode", function () { hints.show("o"); }); - mappings.add(myModes, ["F"], + bind(["F"], "Start Hints mode, but open link in a new tab", function () { hints.show(options.get("activate").has("links") ? "t" : "b"); }); - mappings.add(myModes, [";"], + bind([";"], "Start an extended hints mode", function ({ count }) { hints.open(";", { count: count }); }, { count: true }); - mappings.add(myModes, ["g;"], + bind(["g;"], "Start an extended hints mode and stay there until is pressed", function ({ count }) { hints.open("g;", { continue: true, count: count }); }, { count: true }); - mappings.add(modes.HINTS, [""], + bind([""], "Follow the selected hint", function ({ self }) { self.update(true); }); - mappings.add(modes.HINTS, [""], + bind([""], "Focus the next matching hint", function ({ self }) { self.tab(false); }); - mappings.add(modes.HINTS, [""], + bind([""], "Focus the previous matching hint", function ({ self }) { self.tab(true); }); - mappings.add(modes.HINTS, ["", ""], + bind(["", ""], "Delete the previous character", function ({ self }) self.backspace()); - mappings.add(modes.HINTS, [""], + bind([""], "Toggle hint filtering", function ({ self }) { self.escapeNumbers = !self.escapeNumbers; }); }, diff --git a/common/content/mappings.js b/common/content/mappings.js index c6bb5230..935f06cf 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -341,7 +341,7 @@ var Mappings = Module("mappings", { this._watchStack = 0; this.watches = this.watches.filter(function (elem) { - if (elem[2] <= this._watchStack) + if (this._watchStack <= elem[2]) elem[3]--; if (elem[3] <= 0) elem[0].call(elem[1] || null); diff --git a/common/content/mow.js b/common/content/mow.js index aa4c5b76..6be1f2cd 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -325,6 +325,11 @@ var MOW = Module("mow", { mow.echo(mow.lastOutput, "Normal"); }); + mappings.add([modes.OUTPUT_MULTILINE], + ["", ""], + "Return to the previous mode", + function () { modes.pop(null, { fromEscape: true }); }); + let bind = function bind(keys, description, action, test, default_) { mappings.add([modes.OUTPUT_MULTILINE], keys, description, diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 19c5cb3d..0fc93393 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -2089,7 +2089,7 @@ var Buffer = Module("Buffer", { function () { tabs.reload(tabs.getTab(), true); }); // yanking - mappings.add([modes.COMMAND], ["Y", ""], + mappings.add([modes.NORMAL], ["Y", ""], "Copy selected text or current word", function () { let sel = buffer.currentWord;