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
// TODO: ...help me...please...
onKeyPress: function onKeyPress(event) {
event.dactylDefaultPrevented = event.getPreventDefault();
function kill(event) {
event.preventDefault();
event.stopPropagation();
@@ -963,30 +965,29 @@ var Events = Module("events", {
return null;
if (overrideMode)
processors = [Events.KeyProcessor(overrideMode, mode.extended)];
else {
let keyModes = array([mode.params.keyModes, mode.main, mode.main.allBases]).flatten().compact();
var keyModes = array([overrideMode]);
else
keyModes = array([mode.params.keyModes, mode.main, mode.main.allBases]).flatten().compact();
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;
for (let [i, input] in Iterator(processors)) {
if (input.main == mode.main) {
if (mode.params.preExecute)
input.preExecute = mode.params.preExecute;
if (mode.params.postExecute)
input.postExecute = mode.params.postExecute;
if (mode.params.onEvent && input.hive === mappings.builtinHive)
let params = input.main == mode.main ? mode.params : input.main.params;
if (params.preExecute)
input.preExecute = params.preExecute;
if (params.postExecute)
input.postExecute = params.postExecute;
if (params.onEvent && input.hive === mappings.builtinHive)
input.fallthrough = function (event) {
// Bloody hell.
if (events.toString(event) === "<C-h>")
event.dactylString = "<BS>";
return mode.params.onEvent(event) === false ? Events.KILL : Events.PASS;
return params.onEvent(event) === false ? Events.KILL : Events.PASS;
};
}}
}
}
@@ -1013,9 +1014,9 @@ var Events = Module("events", {
else if (res === Events.KILL && (mode.main & (modes.TEXT_EDIT | modes.VISUAL)))
dactyl.beep();
if (refeed && refeed[0] && !refeed[0].getPreventDefault()) {
if (refeed && refeed[0] && (!refeed[0].getPreventDefault() || refeed[0].dactylDefaultPrevented)) {
res = Events.PASS;
refeed.pop();
refeed.shift();
}
if (res !== Events.PASS)
@@ -1024,7 +1025,6 @@ var Events = Module("events", {
if (refeed)
for (let [i, event] in Iterator(refeed))
if (event.originalTarget) {
util.dump("Re-feed " + i + " " + refeed.length + " " + (events.toString(event) || "").quote());
let evt = events.create(event.originalTarget.ownerDocument, event.type, event);
events.dispatch(event.originalTarget, evt, { skipmap: true });
}
@@ -1111,14 +1111,15 @@ var Events = Module("events", {
KeyProcessor: Class("KeyProcessor", {
init: function init(main, extended, hive) {
init: function init(main, hive) {
this.main = main;
this.extended = extended;
this.events = [];
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
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) {
function kill(event) {
util.dumpStack("kill " + events.toString(event));
event.stopPropagation();
event.preventDefault();
}
@@ -1166,12 +1168,14 @@ var Events = Module("events", {
},
onKeyPress: function onKeyPress(event) {
// This all needs to go. It's horrible. --Kris
const self = this;
let key = events.toString(event);
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) {
if (self.preExecute)

View File

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

View File

@@ -436,11 +436,11 @@ var Modes = Module("modes", {
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,

View File

@@ -1315,7 +1315,7 @@ var array = Class("array", Array, {
* @param {Array} ary
* @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.