diff --git a/common/content/commandline.js b/common/content/commandline.js index 3ea1aeab..3078810c 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -380,8 +380,7 @@ var CommandMode = Class("CommandMode", { keepCommand: false, - onKeyPress: function onKeyPress(event) { - let key = events.toString(event); + onKeyPress: function onKeyPress(events) { if (this.completions) this.completions.previewClear(); diff --git a/common/content/events.js b/common/content/events.js index a55d9161..9bbd230a 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -27,8 +27,8 @@ var ProcessorStack = Class("ProcessorStack", { if (params.postExecute) input.postExecute = params.postExecute; if (params.onKeyPress && input.hive === mappings.builtin) - input.fallthrough = function (event) { - return params.onKeyPress(event) === false ? Events.KILL : Events.PASS; + input.fallthrough = function fallthrough(events) { + return params.onKeyPress(events) === false ? Events.KILL : Events.PASS; }; } }, @@ -84,17 +84,7 @@ var ProcessorStack = Class("ProcessorStack", { let list = this.events.filter(function (e) e.getPreventDefault() && !e.dactylDefaultPrevented); if (list.length) events.dbg("REFEED: " + list.map(events.closure.toString).join("")); - - list.forEach(function (event, i) { - let elem = event.originalTarget; - if (event.originalTarget) { - let doc = elem.ownerDocument || elem.document || elem; - let evt = events.create(doc, event.type, event); - events.dispatch(elem, evt, { skipmap: true, isMacro: true, isReplay: true }); - } - else if (i > 0) - events.events.keypress.call(events, event); - }); + events.feedevents(null, list, { skipmap: true, isMacro: true, isReplay: true }); } if (force && this.processors.length === 0) @@ -153,7 +143,7 @@ var ProcessorStack = Class("ProcessorStack", { if (input.fallthrough) { if (result === Events.KILL) break; - result = dactyl.trapErrors(input.fallthrough, input, event); + result = dactyl.trapErrors(input.fallthrough, input, this.events); } this.processors = processors; @@ -557,6 +547,29 @@ var Events = Module("events", { } }, + /** + * Feeds a list of events to *target* or the originalTarget member + * of each event if *target* is null. + * + * @param {EventTarget} target The destination node for the events. + * @optional + * @param {[Event]} list The events to dispatch. + * @param {object} extra Extra properties for processing by dactyl. + * @optional + */ + feedevents: function feedevents(target, list, extra) { + list.forEach(function (event, i) { + let elem = target || event.originalTarget; + if (elem) { + let doc = elem.ownerDocument || elem.document || elem; + let evt = events.create(doc, event.type, event); + events.dispatch(elem, evt, extra); + } + else if (i > 0 && event.type === "keypress") + events.events.keypress.call(events, event); + }); + }, + /** * Pushes keys onto the event queue from dactyl. It is similar to * Vim's feedkeys() method, but cannot cope with 2 partially-fed diff --git a/common/content/hints.js b/common/content/hints.js index 9bb5293b..d6db07cb 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -357,9 +357,9 @@ var HintSession = Class("HintSession", CommandMode, { * * @param {Event} event The event to handle. */ - onKeyPress: function onKeyPress(event) { + onKeyPress: function onKeyPress(events) { const KILL = false, PASS = true; - let key = events.toString(event); + let key = events.toString(events[0]); this.clearTimeout(); diff --git a/common/content/modes.js b/common/content/modes.js index 4321e64d..598ee011 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -144,10 +144,10 @@ var Modes = Module("modes", { // Fix me. preExecute: function (map) { if (modes.main == modes.QUOTE && map.name !== "") modes.pop(); }, postExecute: function (map) { if (modes.main == modes.QUOTE && map.name === "") modes.pop(); }, - onKeyPress: function () { if (modes.main == modes.QUOTE) modes.pop() } + onKeyPress: function (events) { if (modes.main == modes.QUOTE) modes.pop(); } }); this.addMode("IGNORE", { hidden: true }, { - onKeyPress: function (event) Events.KILL, + onKeyPress: function (events) Events.KILL, bases: [], passthrough: true }); diff --git a/common/content/mow.js b/common/content/mow.js index bf227f4f..7d6d05b5 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -210,14 +210,14 @@ var MOW = Module("mow", { } }, - onKeyPress: function onKeyPress(event) { + onKeyPress: function onKeyPress(eventList) { const KILL = false, PASS = true; if (options["more"] && mow.isScrollable(1)) this.updateMorePrompt(false, true); else { modes.pop(); - events.feedkeys(events.toString(event)); + events.feedevents(null, eventList); return KILL; } return PASS;