diff --git a/common/content/events.js b/common/content/events.js index c64dee02..7eb1b637 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -1013,7 +1013,7 @@ var Events = Module("events", { DOMMenuBarInactive: function () { this._activeMenubar = false; - modes.remove(modes.MENU); + modes.remove(modes.MENU, true); }, blur: function onBlur(event) { @@ -1244,7 +1244,7 @@ var Events = Module("events", { popuphidden: function onPopupHidden() { // gContextMenu is set to NULL, when a context menu is closed if (window.gContextMenu == null && !this._activeMenubar) - modes.remove(modes.MENU); + modes.remove(modes.MENU, true); }, resize: function onResize(event) { diff --git a/common/content/modes.js b/common/content/modes.js index 837682fc..76a967a0 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -155,7 +155,15 @@ var Modes = Module("modes", { this.addMode("MENU", { description: "Active when a menu or other pop-up is open", input: true, - passthrough: true + passthrough: true, + ownsInput: false + }, { + leave: function leave(stack) { + util.timeout(function () { + if (stack.pop && !modes.main.input && !Events.isInputElement(dactyl.focusedElement)); + modes.push(modes.INSERT); + }); + } }); this.addMode("LINE", { @@ -260,8 +268,13 @@ var Modes = Module("modes", { commandline.widgets.mode = msg || null; }, - remove: function remove(mode) { - if (this.stack.some(function (m) m.main == mode)) { + remove: function remove(mode, covert) { + if (covert && this.topOfStack.main != mode) { + util.assert(mode != this.NORMAL); + for (let m; m = array.nth(this.modeStack, function (m) m.main == mode, 0);) + this._modeStack.splice(this._modeStack.indexOf(m)); + } + else if (this.stack.some(function (m) m.main == mode)) { this.pop(mode); this.pop(); }