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

Get rid of absurd Map#route flag. Consolodate some constants.

This commit is contained in:
Kris Maglione
2011-01-18 17:35:57 -05:00
parent 3e95b19cb0
commit c78bb0f332
9 changed files with 52 additions and 50 deletions

View File

@@ -31,7 +31,7 @@ XPI_DIRS = components $(MANGLE) defaults
XPI_TEXTS = js jsm $(JAR_TEXTS) XPI_TEXTS = js jsm $(JAR_TEXTS)
XPI_BINS = $(JAR_BINS) XPI_BINS = $(JAR_BINS)
XPI_NAME = $(NAME)_$(VERSION) XPI_NAME = $(NAME)-$(VERSION)
XPI_PATH = ../downloads/$(XPI_NAME) XPI_PATH = ../downloads/$(XPI_NAME)
XPI = $(XPI_PATH).xpi XPI = $(XPI_PATH).xpi

View File

@@ -1713,9 +1713,8 @@ var CommandLine = Module("commandline", {
function () { function () {
commandline.resetCompletions(); commandline.resetCompletions();
editor.expandAbbreviation(modes.COMMAND_LINE); editor.expandAbbreviation(modes.COMMAND_LINE);
return true; return Events.PASS;
}, });
{ route: true });
mappings.add(myModes, mappings.add(myModes,
["<C-]>", "<C-5>"], "Expand command line abbreviation", ["<C-]>", "<C-5>"], "Expand command line abbreviation",

View File

@@ -588,8 +588,10 @@ var Editor = Module("editor", {
mappings.add([modes.INSERT], mappings.add([modes.INSERT],
["<Space>", "<Return>"], "Expand insert mode abbreviation", ["<Space>", "<Return>"], "Expand insert mode abbreviation",
function () { editor.expandAbbreviation(modes.INSERT); }, function () {
{ route: true }); editor.expandAbbreviation(modes.INSERT);
return Events.PASS;
});
mappings.add([modes.INSERT], mappings.add([modes.INSERT],
["<C-]>", "<C-5>"], "Expand insert mode abbreviation", ["<C-]>", "<C-5>"], "Expand insert mode abbreviation",

View File

@@ -978,26 +978,24 @@ var Events = Module("events", {
if (events.toString(event) === "<C-h>") if (events.toString(event) === "<C-h>")
event.dactylString = "<BS>"; event.dactylString = "<BS>";
return mode.params.onEvent(event) === false ? KILL : PASS; return mode.params.onEvent(event) === false ? Events.KILL : Events.PASS;
}; };
}} }}
} }
} }
const KILL = true, PASS = false, WAIT = null;
let refeed, ownsBuffer = 0, buffer, waiting = 0; let refeed, ownsBuffer = 0, buffer, waiting = 0;
for (let input in values(processors)) { for (let input in values(processors)) {
var res = input.process(event); var res = input.process(event);
ownsBuffer += !!input.main.ownsBuffer; ownsBuffer += !!input.main.ownsBuffer;
waiting += res == WAIT; waiting += res == Events.WAIT;
buffer = buffer || input.inputBuffer; buffer = buffer || input.inputBuffer;
if (isArray(res) && !waiting) if (isArray(res) && !waiting)
refeed = res; refeed = res;
else if (res !== PASS) else if (res !== Events.PASS)
refeed = null; refeed = null;
if (res === KILL) if (res === Events.KILL)
break; break;
} }
@@ -1006,13 +1004,15 @@ var Events = Module("events", {
if (waiting) if (waiting)
this._processors = processors; this._processors = processors;
else if (res !== KILL && (mode.main & (modes.TEXT_EDIT | modes.VISUAL))) else if (res !== Events.KILL && (mode.main & (modes.TEXT_EDIT | modes.VISUAL)))
dactyl.beep(); dactyl.beep();
if (refeed && refeed.length == 1 && !refeed[0].getPreventDefault()) if (refeed && refeed[0] && !refeed[0].getPreventDefault()) {
[refeed, res] = [null, PASS]; res = Events.PASS;
refeed.pop();
}
if (res !== PASS) if (res !== Events.PASS)
kill(event); kill(event);
if (refeed) if (refeed)
@@ -1097,6 +1097,11 @@ var Events = Module("events", {
} }
} }
}, { }, {
KILL: true,
PASS: false,
WAIT: null,
KeyProcessor: Class("KeyProcessor", { KeyProcessor: Class("KeyProcessor", {
init: function init(main, extended, hive) { init: function init(main, extended, hive) {
this.main = main; this.main = main;
@@ -1105,7 +1110,7 @@ var Events = Module("events", {
this.hive = hive; this.hive = hive;
}, },
toString: function () ["[instance KeyProcessor(" + this.main.name, this.extended, this.hive.name + ")]"].join(", "), get toStringParams() [this.main.name, this.extended, this.hive.name],
buffer: "", // partial command storage buffer: "", // partial command storage
pendingMotionMap: null, // e.g. "d{motion}" if we wait for a motion of the "d" command pendingMotionMap: null, // e.g. "d{motion}" if we wait for a motion of the "d" command
@@ -1120,31 +1125,29 @@ var Events = Module("events", {
}, },
process: function process(event) { process: function process(event) {
const KILL = true, PASS = false, WAIT = null;
function kill(event) { function kill(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
} }
let res = this.onKeyPress(event); let res = this.onKeyPress(event);
if (res === KILL) if (res === Events.KILL)
kill(event); kill(event);
else if (this.fallthrough) { else if (this.fallthrough) {
let evt = isArray(res) ? res[0] : event; let evt = isArray(res) ? res[0] : event;
let r = dactyl.trapErrors(this.fallthrough, this, evt); let r = dactyl.trapErrors(this.fallthrough, this, evt);
if (r === KILL) if (r === Events.KILL)
kill(evt); kill(evt);
res = r === KILL ? KILL : PASS; res = r === Events.KILL ? Events.KILL : Events.PASS;
/* /*
if (r === KILL) if (r === Events.KILL)
res = res.slice(1); res = res.slice(1);
else else
res = r == WAIT ? res : false; res = r == Events.WAIT ? res : false;
*/ */
} }
if (res != WAIT) if (res != Events.WAIT)
this.inputBuffer = ""; this.inputBuffer = "";
else { else {
let motionMap = (this.pendingMotionMap && this.pendingMotionMap.names[0]) || ""; let motionMap = (this.pendingMotionMap && this.pendingMotionMap.names[0]) || "";
@@ -1155,7 +1158,6 @@ var Events = Module("events", {
}, },
onKeyPress: function onKeyPress(event) { onKeyPress: function onKeyPress(event) {
const KILL = true, PASS = false, WAIT = null;
const self = this; const self = this;
let key = events.toString(event); let key = events.toString(event);
@@ -1186,7 +1188,7 @@ var Events = Module("events", {
if (!this.main.count) if (!this.main.count)
return this.append(event); return this.append(event);
else if (this.main.input) else if (this.main.input)
return PASS; return Events.PASS;
else else
this.append(event); this.append(event);
} }
@@ -1194,7 +1196,7 @@ var Events = Module("events", {
let [map, command] = this.pendingArgMap; let [map, command] = this.pendingArgMap;
if (!Events.isEscape(key)) if (!Events.isEscape(key))
execute(map, null, this.count, key, command); execute(map, null, this.count, key, command);
return KILL; return Events.KILL;
} }
else if (!event.skipmap && map && candidates.length == 0) { else if (!event.skipmap && map && candidates.length == 0) {
this.pendingMap = null; this.pendingMap = null;
@@ -1213,7 +1215,7 @@ var Events = Module("events", {
let [map, command] = this.pendingMotionMap; let [map, command] = this.pendingMotionMap;
if (!Events.isEscape(key)) if (!Events.isEscape(key))
execute(map, command, this.motionCount || this.count, null, command); execute(map, command, this.motionCount || this.count, null, command);
return KILL; return Events.KILL;
} }
else if (map.motion) { else if (map.motion) {
this.buffer = ""; this.buffer = "";
@@ -1221,9 +1223,9 @@ var Events = Module("events", {
} }
else { else {
if (modes.replaying && !events.waitForPageLoad()) if (modes.replaying && !events.waitForPageLoad())
return KILL; return Events.KILL;
return execute(map, null, this.count, null, command) && map.route ? PASS : KILL; return execute(map, null, this.count, null, command) === Events.PASS ? Events.PASS : Events.KILL;
} }
} }
else if (!event.skipmap && this.hive.getCandidates(this.main, command).length > 0) { else if (!event.skipmap && this.hive.getCandidates(this.main, command).length > 0) {
@@ -1234,7 +1236,7 @@ var Events = Module("events", {
this.append(event); this.append(event);
return this.events; return this.events;
} }
return WAIT; return Events.WAIT;
} }
}), }),
@@ -1291,10 +1293,9 @@ var Events = Module("events", {
["<C-v>"], "Pass through next key", ["<C-v>"], "Pass through next key",
function () { function () {
if (modes.main == modes.QUOTE) if (modes.main == modes.QUOTE)
return true; return Events.PASS;
modes.push(modes.QUOTE); modes.push(modes.QUOTE);
}, });
{ route: true });
mappings.add(modes.all, mappings.add(modes.all,
["<Nop>"], "Do nothing", ["<Nop>"], "Do nothing",

View File

@@ -1120,7 +1120,7 @@ var Hints = Module("hints", {
function () { function () {
hints.clearTimeout(); hints.clearTimeout();
if (hints.prevInput !== "number") if (hints.prevInput !== "number")
return true; return Events.PASS;
if (hints._hintNumber > 0 && !hints._usedTabKey) { if (hints._hintNumber > 0 && !hints._usedTabKey) {
hints._hintNumber = Math.floor(hints._hintNumber / hints.hintKeys.length); hints._hintNumber = Math.floor(hints._hintNumber / hints.hintKeys.length);
@@ -1133,9 +1133,8 @@ var Hints = Module("hints", {
hints._hintNumber = 0; hints._hintNumber = 0;
dactyl.beep(); dactyl.beep();
} }
return false; return Events.KILL;
}, });
{ route: true });
mappings.add(modes.HINTS, ["<Leader>"], mappings.add(modes.HINTS, ["<Leader>"],
"Toggle hint filtering", "Toggle hint filtering",

View File

@@ -22,7 +22,6 @@
* arg - see {@link Map#arg} * arg - see {@link Map#arg}
* count - see {@link Map#count} * count - see {@link Map#count}
* motion - see {@link Map#motion} * motion - see {@link Map#motion}
* route - see {@link Map#route}
* noremap - see {@link Map#noremap} * noremap - see {@link Map#noremap}
* rhs - see {@link Map#rhs} * rhs - see {@link Map#rhs}
* silent - see {@link Map#silent} * silent - see {@link Map#silent}
@@ -49,6 +48,8 @@ var Map = Class("Map", {
update(this, extraInfo); update(this, extraInfo);
}, },
get toStringParams() [this.modes.map(function (m) m.name), this.names.map(String.quote)],
/** @property {number[]} All of the modes for which this mapping applies. */ /** @property {number[]} All of the modes for which this mapping applies. */
modes: null, modes: null,
/** @property {string[]} All of this mapping's names (key sequences). */ /** @property {string[]} All of this mapping's names (key sequences). */
@@ -67,12 +68,6 @@ var Map = Class("Map", {
* as an argument. * as an argument.
*/ */
motion: false, motion: false,
/**
* @property {boolean} Whether the mapping's key events should be
* propagated to the host application.
*/
// TODO: I'm not sure this is the best name but it reflects that which it replaced. --djk
route: false,
/** @property {boolean} Whether the RHS of the mapping should expand mappings recursively. */ /** @property {boolean} Whether the RHS of the mapping should expand mappings recursively. */
noremap: false, noremap: false,
/** @property {boolean} Whether any output from the mapping should be echoed on the command line. */ /** @property {boolean} Whether any output from the mapping should be echoed on the command line. */
@@ -128,6 +123,8 @@ var MapHive = Class("MapHive", {
this.stacks = {}; this.stacks = {};
}, },
get toStringParams() [this.name],
/** /**
* Iterates over all mappings present in all of the given *modes*. * Iterates over all mappings present in all of the given *modes*.
* *

View File

@@ -766,7 +766,12 @@ Class.prototype = {
} }
}, },
toString: function () "[instance " + this.constructor.className + "]", toString: function () {
if (this.toStringParams)
var params = "(" + this.toStringParams.map(function (m) isArray(m) ? "[" + m + "]" :
isString(m) ? m.quote() : String(m)) + ")";
return "[instance " + this.constructor.className + (params || "") + "]";
},
/** /**
* Executes *callback* after *timeout* milliseconds. The value of * Executes *callback* after *timeout* milliseconds. The value of

View File

@@ -108,7 +108,7 @@ var RangeFinder = Module("rangefinder", {
}, 0); }, 0);
else else
this.commandline.echo((this.rangeFind.backward ? "?" : "/") + this.lastFindPattern, this.commandline.echo((this.rangeFind.backward ? "?" : "/") + this.lastFindPattern,
null, this.commandline.FORCE_SINGLELINE); "Normal", this.commandline.FORCE_SINGLELINE);
if (this.options["hlfind"]) if (this.options["hlfind"])
this.highlight(); this.highlight();

View File

@@ -514,8 +514,7 @@ const Mail = Module("mail", {
mappings.add(myModes, ["<Space>"], mappings.add(myModes, ["<Space>"],
"Scroll message or select next unread one", "Scroll message or select next unread one",
function () true, function () Events.PASS);
{ route: true });
mappings.add(myModes, ["t"], mappings.add(myModes, ["t"],
"Select thread", "Select thread",