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

Key processing cleanup and bug fixes.

This commit is contained in:
Kris Maglione
2011-01-19 00:35:53 -05:00
parent e28b009036
commit 9546a7adb6
4 changed files with 37 additions and 33 deletions

View File

@@ -881,6 +881,8 @@ var Events = Module("events", {
// the command-line has focus // the command-line has focus
// TODO: ...help me...please... // TODO: ...help me...please...
onKeyPress: function onKeyPress(event) { onKeyPress: function onKeyPress(event) {
event.dactylDefaultPrevented = event.getPreventDefault();
function kill(event) { function kill(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@@ -963,31 +965,30 @@ var Events = Module("events", {
return null; return null;
if (overrideMode) if (overrideMode)
processors = [Events.KeyProcessor(overrideMode, mode.extended)]; var keyModes = array([overrideMode]);
else { else
let keyModes = array([mode.params.keyModes, mode.main, mode.main.allBases]).flatten().compact(); keyModes = array([mode.params.keyModes, mode.main, mode.main.allBases]).flatten().compact();
let hives = mappings.hives.slice(event.noremap ? -1 : 0); let hives = mappings.hives.slice(event.noremap ? -1 : 0);
processors = keyModes.map(function (m) hives.map(function (h) Events.KeyProcessor(m, mode.extended, h))) processors = keyModes.map(function (m) hives.map(function (h) Events.KeyProcessor(m, h)))
.flatten().array; .flatten().array;
for (let [i, input] in Iterator(processors)) { for (let [i, input] in Iterator(processors)) {
if (input.main == mode.main) { let params = input.main == mode.main ? mode.params : input.main.params;
if (mode.params.preExecute) if (params.preExecute)
input.preExecute = mode.params.preExecute; input.preExecute = params.preExecute;
if (mode.params.postExecute) if (params.postExecute)
input.postExecute = mode.params.postExecute; input.postExecute = params.postExecute;
if (mode.params.onEvent && input.hive === mappings.builtinHive) if (params.onEvent && input.hive === mappings.builtinHive)
input.fallthrough = function (event) { input.fallthrough = function (event) {
// Bloody hell. // Bloody hell.
if (events.toString(event) === "<C-h>") if (events.toString(event) === "<C-h>")
event.dactylString = "<BS>"; event.dactylString = "<BS>";
return mode.params.onEvent(event) === false ? Events.KILL : Events.PASS; return params.onEvent(event) === false ? Events.KILL : Events.PASS;
}; };
}} }
}
} }
let refeed, ownsBuffer = 0, buffer, waiting = 0; let refeed, ownsBuffer = 0, buffer, waiting = 0;
@@ -1013,9 +1014,9 @@ var Events = Module("events", {
else if (res === Events.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[0] && !refeed[0].getPreventDefault()) { if (refeed && refeed[0] && (!refeed[0].getPreventDefault() || refeed[0].dactylDefaultPrevented)) {
res = Events.PASS; res = Events.PASS;
refeed.pop(); refeed.shift();
} }
if (res !== Events.PASS) if (res !== Events.PASS)
@@ -1024,7 +1025,6 @@ var Events = Module("events", {
if (refeed) if (refeed)
for (let [i, event] in Iterator(refeed)) for (let [i, event] in Iterator(refeed))
if (event.originalTarget) { if (event.originalTarget) {
util.dump("Re-feed " + i + " " + refeed.length + " " + (events.toString(event) || "").quote());
let evt = events.create(event.originalTarget.ownerDocument, event.type, event); let evt = events.create(event.originalTarget.ownerDocument, event.type, event);
events.dispatch(event.originalTarget, evt, { skipmap: true }); events.dispatch(event.originalTarget, evt, { skipmap: true });
} }
@@ -1111,14 +1111,15 @@ var Events = Module("events", {
KeyProcessor: Class("KeyProcessor", { KeyProcessor: Class("KeyProcessor", {
init: function init(main, extended, hive) { init: function init(main, hive) {
this.main = main; this.main = main;
this.extended = extended;
this.events = []; this.events = [];
this.hive = hive; this.hive = hive;
if (!hive.get)
util.dumpStack(main + " " + hive + " !hive.get")
}, },
get toStringParams() [this.main.name, this.extended, this.hive.name], get toStringParams() [this.main.name, 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
@@ -1134,6 +1135,7 @@ var Events = Module("events", {
process: function process(event) { process: function process(event) {
function kill(event) { function kill(event) {
util.dumpStack("kill " + events.toString(event));
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
} }
@@ -1166,12 +1168,14 @@ var Events = Module("events", {
}, },
onKeyPress: function onKeyPress(event) { onKeyPress: function onKeyPress(event) {
// This all needs to go. It's horrible. --Kris
const self = this; const self = this;
let key = events.toString(event); let key = events.toString(event);
let [, countStr, command] = /^((?:[1-9][0-9]*)?)(.*)/.exec(this.buffer + key); let [, countStr, command] = /^((?:[1-9][0-9]*)?)(.*)/.exec(this.buffer + key);
let map = this.hive.get(this.main, command); var map = this.hive.get(this.main, command);
function execute(map) { function execute(map) {
if (self.preExecute) if (self.preExecute)

View File

@@ -654,7 +654,7 @@ var Mappings = Module("mappings", {
if (mode.char && !commands.get(mode.char + "map", true)) if (mode.char && !commands.get(mode.char + "map", true))
addMapCommands(mode.char, addMapCommands(mode.char,
[m.mask for (m in modes.mainModes) if (m.char == mode.char)], [m.mask for (m in modes.mainModes) if (m.char == mode.char)],
[mode.disp.toLowerCase()]); [mode.name.toLowerCase()]);
}, },
completion: function () { completion: function () {
completion.userMapping = function userMapping(context, modes) { completion.userMapping = function userMapping(context, modes) {

View File

@@ -436,11 +436,11 @@ var Modes = Module("modes", {
count: true, count: true,
get description() this.disp, get description() this._display,
disp: Class.memoize(function () this.name.replace("_", " ", "g")), _display: Class.memoize(function () this.name.replace("_", " ", "g")),
display: function () this.disp, display: function () this._display,
extended: false, extended: false,

View File

@@ -1315,7 +1315,7 @@ var array = Class("array", Array, {
* @param {Array} ary * @param {Array} ary
* @returns {Array} * @returns {Array}
*/ */
flatten: function flatten(ary) ary.length ? Array.concat.apply([], ary) : [], flatten: function flatten(ary) ary.length ? Array.prototype.concat.apply([], ary) : [],
/** /**
* Returns an Iterator for an array's values. * Returns an Iterator for an array's values.