diff --git a/common/content/events.js b/common/content/events.js index 8eb3b23e..6ad494b3 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -688,13 +688,17 @@ const Events = Module("events", { // TODO: Merge with onFocusChange onFocus: function onFocus(event) { let elem = event.originalTarget; + if (elem instanceof Element) { + let win = elem.ownerDocument.defaultView; - if (Events.isContentNode(elem) && !buffer.focusAllowed(elem) - && isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, Window])) { - if (elem.frameElement) - dactyl.focusContent(true); - else if (!(elem instanceof Window) || Editor.getEditor(elem)) - elem.blur(); + if (Events.isContentNode(elem) && !buffer.focusAllowed(elem) + && !(services.focus.getLastFocusMethod(win) & 0x7000) + && isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, Window])) { + if (elem.frameElement) + dactyl.focusContent(true); + else if (!(elem instanceof Window) || Editor.getEditor(elem)) + elem.blur(); + } } }, @@ -734,6 +738,7 @@ const Events = Module("events", { let win = window.document.commandDispatcher.focusedWindow; let elem = window.document.commandDispatcher.focusedElement; + if (elem == null && Editor.getEditor(win)) elem = win; @@ -790,7 +795,7 @@ const Events = Module("events", { util.threadYield(true); while (modes.main.ownsFocus) - modes.pop(); + modes.pop(null, { fromFocus: true }); } finally { this._lastFocus = elem; @@ -1136,15 +1141,6 @@ const Events = Module("events", { [":"], "Enter command-line mode", function () { commandline.open(":", "", modes.EX); }); - // focus events - mappings.add([modes.NORMAL, modes.PLAYER, modes.VISUAL, modes.CARET].filter(util.identity), - [""], "Advance keyboard focus", - function () { document.commandDispatcher.advanceFocus(); }); - - mappings.add([modes.NORMAL, modes.PLAYER, modes.VISUAL, modes.CARET, modes.INSERT, modes.TEXT_EDIT].filter(util.identity), - [""], "Rewind keyboard focus", - function () { document.commandDispatcher.rewindFocus(); }); - mappings.add(modes.all, [""], "Temporarily ignore all " + config.appName + " key bindings", function () { modes.push(modes.PASS_THROUGH); }); diff --git a/common/content/modes.js b/common/content/modes.js index ad9cd942..cc57ebf1 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -90,7 +90,7 @@ const Modes = Module("modes", { prefs.set("accessibility.browsewithcaret", false); statusline.updateUrl(); - if (prev.mainMode.input || prev.mainMode.ownsFocus) + if (!stack.fromFocus && (prev.mainMode.input || prev.mainMode.ownsFocus)) dactyl.focusContent(true); if (prev.main == modes.NORMAL) { dactyl.focusContent(true); @@ -275,11 +275,11 @@ const Modes = Module("modes", { this.set(mainMode, extendedMode, params, { push: this.topOfStack }); }, - pop: function pop(mode) { + pop: function pop(mode, args) { while (this._modeStack.length > 1 && this.main != mode) { let a = this._modeStack.pop(); this.set(this.topOfStack.main, this.topOfStack.extended, this.topOfStack.params, - { pop: a }); + update({ pop: a }, args || {})); if (mode == null) return;