From 2eef6020d3554b161e396914a9ab29123c863664 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 17 Oct 2015 22:42:08 +0200 Subject: [PATCH] Fix slightly broken `` handling --- extension/lib/commands.coffee | 4 +--- extension/lib/modes.coffee | 4 ++-- extension/lib/utils.coffee | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 705c9f7..d55ec9c 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -391,9 +391,7 @@ commands.dev = ({ vim }) -> commands.esc = ({ vim }) -> vim._run('esc') - # Some browser UI elements, such as the web console, are not marked as - # focusable, so we need to force the blur. - utils.blurActiveElement(vim.window, {force: true}) + utils.blurActiveBrowserElement(vim.window) help.removeHelp(vim.window) vim.window.DeveloperToolbar.hide() vim.window.gBrowser.getFindBar().close() diff --git a/extension/lib/modes.coffee b/extension/lib/modes.coffee index 2c16217..c8689ac 100644 --- a/extension/lib/modes.coffee +++ b/extension/lib/modes.coffee @@ -102,9 +102,9 @@ mode('normal', { # markers on it without closing it. Secondly, otherwise cancelling hint # markers on Google causes its search bar to be focused. # - It may only be suppressed in web pages, not in browser chrome. That - # allows for reseting the location bar when blurring it, and closing + # allows for resetting the location bar when blurring it, and closing # dialogs such as the “bookmark this page” dialog (). - return not (keyStr == '' and not autoInsertMode and isFrameEvent) + return not (keyStr == '' and not (isFrameEvent and autoInsertMode)) }, commands) diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index f8d9f24..49f4a63 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -96,13 +96,27 @@ getActiveElement = (window) -> else return activeElement -blurActiveElement = (window, { force = false } = {}) -> +blurActiveElement = (window) -> # Only blur focusable elements, in order to interfere with the browser as # little as possible. activeElement = getActiveElement(window) - if activeElement and (activeElement.tabIndex > -1 or force) + if activeElement and activeElement.tabIndex > -1 activeElement.blur() +blurActiveBrowserElement = (window) -> + # - Some browser UI elements, such as the web console, are not marked as + # focusable, so we can’t check if the element is focusable as in + # `blurActiveElement`. + # - Blurring in the next tick allows to pass `` to the location bar to + # reset it, for example. + # - Focusing the current browser afterwards allows to pass `` as well + # as unbound keys to the page. + activeElement = getActiveElement(window) + callback = -> + activeElement.blur() + window.gBrowser.selectedBrowser.focus() + window.setTimeout(callback, 0) + # Focus an element and tell Firefox that the focus happened because of a user # keypress (not just because some random programmatic focus). focusElement = (element, options = {}) -> @@ -286,6 +300,7 @@ module.exports = { getActiveElement blurActiveElement + blurActiveBrowserElement focusElement getFocusType -- 2.39.3