1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 07:17:59 +01:00

Hint processing mapping state magic stuff.

This commit is contained in:
Kris Maglione
2011-10-10 02:48:05 -04:00
parent 400ec6244b
commit 798f26c746
4 changed files with 34 additions and 25 deletions

View File

@@ -17,8 +17,6 @@ var HintSession = Class("HintSession", CommandMode, {
opts = opts || {}; opts = opts || {};
this.forceOpen = opts.forceOpen || dactyl.forceOpen;
if (!opts.window) if (!opts.window)
opts.window = modes.getStack(0).params.window; opts.window = modes.getStack(0).params.window;
@@ -36,6 +34,7 @@ var HintSession = Class("HintSession", CommandMode, {
this.usedTabKey = false; this.usedTabKey = false;
this.validHints = []; // store the indices of the "hints" array with valid elements this.validHints = []; // store the indices of the "hints" array with valid elements
mappings.pushCommand();
this.open(); this.open();
this.top = opts.window || content; this.top = opts.window || content;
@@ -99,6 +98,8 @@ var HintSession = Class("HintSession", CommandMode, {
leave.superapply(this, arguments); leave.superapply(this, arguments);
if (!stack.push) { if (!stack.push) {
mappings.popCommand();
if (hints.hintSession == this) if (hints.hintSession == this)
hints.hintSession = null; hints.hintSession = null;
if (this.top) { if (this.top) {
@@ -500,18 +501,17 @@ var HintSession = Class("HintSession", CommandMode, {
this.timeout(next, 50); this.timeout(next, 50);
}).call(this); }).call(this);
mappings.pushCommand();
if (!this.continue) { if (!this.continue) {
modes.pop(); modes.pop();
if (timeout) if (timeout)
modes.push(modes.IGNORE, modes.HINTS); modes.push(modes.IGNORE, modes.HINTS);
} }
dactyl.withSavedValues(["forceOpen"], function () {
dactyl.forceOpen = this.forceOpen;
dactyl.trapErrors("action", this.hintMode, dactyl.trapErrors("action", this.hintMode,
elem, elem.href || elem.src || "", elem, elem.href || elem.src || "",
this.extendedhintCount, top); this.extendedhintCount, top);
}, this); mappings.popCommand();
this.timeout(function () { this.timeout(function () {
if (modes.main == modes.IGNORE && !this.continue) 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("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", 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("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 location", function (elem, loc) editor.setRegister(null, loc, true));
this.addMode("Y", "Yank hint description", function (elem) dactyl.clipboardWrite(elem.textContent || "", 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("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", function (elem) dactyl.open(elem.src));
this.addMode("I", "Show image in a new tab", function (elem) dactyl.open(elem.src, dactyl.NEW_TAB)); 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; this._extendedhintCount = opts.count;
opts = opts || {}; opts = opts || {};
if (!Set.has(opts, "forceOpen"))
opts.forceOpen = dactyl.forceOpen;
commandline.input(["Normal", mode], "", { mappings.pushCommand();
commandline.input(["Normal", mode], null, {
autocomplete: false, autocomplete: false,
completer: function (context) { completer: function (context) {
context.compare = function () 0; context.compare = function () 0;
context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))]; context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))];
}, },
onCancel: mappings.closure.popCommand,
onSubmit: function (arg) { onSubmit: function (arg) {
if (arg) if (arg)
hints.show(arg, opts); hints.show(arg, opts);
mappings.popCommand();
}, },
onChange: function (arg) { onChange: function (arg) {
if (Object.keys(hints.modes).some(function (m) m != arg && m.indexOf(arg) == 0)) if (Object.keys(hints.modes).some(function (m) m != arg && m.indexOf(arg) == 0))
@@ -1216,42 +1217,45 @@ var Hints = Module("hints", {
}); });
}, },
mappings: function () { mappings: function () {
var myModes = config.browserModes.concat(modes.OUTPUT_MULTILINE); let bind = function bind(names, description, action, params)
mappings.add(myModes, ["f"], mappings.add(config.browserModes, names, description,
action, params);
bind(["f"],
"Start Hints mode", "Start Hints mode",
function () { hints.show("o"); }); function () { hints.show("o"); });
mappings.add(myModes, ["F"], bind(["F"],
"Start Hints mode, but open link in a new tab", "Start Hints mode, but open link in a new tab",
function () { hints.show(options.get("activate").has("links") ? "t" : "b"); }); function () { hints.show(options.get("activate").has("links") ? "t" : "b"); });
mappings.add(myModes, [";"], bind([";"],
"Start an extended hints mode", "Start an extended hints mode",
function ({ count }) { hints.open(";", { count: count }); }, function ({ count }) { hints.open(";", { count: count }); },
{ count: true }); { count: true });
mappings.add(myModes, ["g;"], bind(["g;"],
"Start an extended hints mode and stay there until <Esc> is pressed", "Start an extended hints mode and stay there until <Esc> is pressed",
function ({ count }) { hints.open("g;", { continue: true, count: count }); }, function ({ count }) { hints.open("g;", { continue: true, count: count }); },
{ count: true }); { count: true });
mappings.add(modes.HINTS, ["<Return>"], bind(["<Return>"],
"Follow the selected hint", "Follow the selected hint",
function ({ self }) { self.update(true); }); function ({ self }) { self.update(true); });
mappings.add(modes.HINTS, ["<Tab>"], bind(["<Tab>"],
"Focus the next matching hint", "Focus the next matching hint",
function ({ self }) { self.tab(false); }); function ({ self }) { self.tab(false); });
mappings.add(modes.HINTS, ["<S-Tab>"], bind(["<S-Tab>"],
"Focus the previous matching hint", "Focus the previous matching hint",
function ({ self }) { self.tab(true); }); function ({ self }) { self.tab(true); });
mappings.add(modes.HINTS, ["<BS>", "<C-h>"], bind(["<BS>", "<C-h>"],
"Delete the previous character", "Delete the previous character",
function ({ self }) self.backspace()); function ({ self }) self.backspace());
mappings.add(modes.HINTS, ["<Leader>"], bind(["<Leader>"],
"Toggle hint filtering", "Toggle hint filtering",
function ({ self }) { self.escapeNumbers = !self.escapeNumbers; }); function ({ self }) { self.escapeNumbers = !self.escapeNumbers; });
}, },

View File

@@ -341,7 +341,7 @@ var Mappings = Module("mappings", {
this._watchStack = 0; this._watchStack = 0;
this.watches = this.watches.filter(function (elem) { this.watches = this.watches.filter(function (elem) {
if (elem[2] <= this._watchStack) if (this._watchStack <= elem[2])
elem[3]--; elem[3]--;
if (elem[3] <= 0) if (elem[3] <= 0)
elem[0].call(elem[1] || null); elem[0].call(elem[1] || null);

View File

@@ -325,6 +325,11 @@ var MOW = Module("mow", {
mow.echo(mow.lastOutput, "Normal"); mow.echo(mow.lastOutput, "Normal");
}); });
mappings.add([modes.OUTPUT_MULTILINE],
["<Esc>", "<C-[>"],
"Return to the previous mode",
function () { modes.pop(null, { fromEscape: true }); });
let bind = function bind(keys, description, action, test, default_) { let bind = function bind(keys, description, action, test, default_) {
mappings.add([modes.OUTPUT_MULTILINE], mappings.add([modes.OUTPUT_MULTILINE],
keys, description, keys, description,

View File

@@ -2089,7 +2089,7 @@ var Buffer = Module("Buffer", {
function () { tabs.reload(tabs.getTab(), true); }); function () { tabs.reload(tabs.getTab(), true); });
// yanking // yanking
mappings.add([modes.COMMAND], ["Y", "<yank-word>"], mappings.add([modes.NORMAL], ["Y", "<yank-word>"],
"Copy selected text or current word", "Copy selected text or current word",
function () { function () {
let sel = buffer.currentWord; let sel = buffer.currentWord;