From 11ade4ed2dae1b6f873d5c33e533f39a03838adf Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 27 Mar 2016 06:50:18 +0100 Subject: Escape closes help dialog. With the help dialog in an iframe, Escape no longer closes it if that iframe loses the focus. This fixes that. See point 2 of #2045. This is not a perfect solution: it only works if the focus ends up in the frame from which the help dialog was launched. However, that is the the common case and, in particular, it is the case which arises on the options page -- which is a particularly important use case. --- content_scripts/mode_key_handler.coffee | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee index bafdfd56..cc9ef10f 100644 --- a/content_scripts/mode_key_handler.coffee +++ b/content_scripts/mode_key_handler.coffee @@ -37,12 +37,17 @@ class KeyHandlerMode extends Mode onKeydown: (event) -> keyChar = KeyboardUtils.getKeyCharString event isEscape = KeyboardUtils.isEscape event - if isEscape and @countPrefix == 0 and @keyState.length == 1 - @continueBubbling - else if isEscape + if isEscape and (@countPrefix != 0 or @keyState.length != 1) @keydownEvents[event.keyCode] = true @reset() false # Suppress event. + # If the help dialog loses the focus, then Escape should hide it; see point 2 in #2045. + else if isEscape and HelpDialog?.showing + @keydownEvents[event.keyCode] = true + HelpDialog.hide() + @stopBubblingAndTrue + else if isEscape + @continueBubbling else if @isMappedKey keyChar @keydownEvents[event.keyCode] = true @handleKeyChar keyChar -- cgit v1.2.3 From 61f207c12a1617132115ce28e3f0262fffe187f4 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 27 Mar 2016 07:40:41 +0100 Subject: Do not hide help dialog on click (on options page). Normally, we close the help dialog when the user clicks outside of it. On the options page, however, the user might want the help dialog open while they type command names into the key-mappings input. Therefore, we disable hide-on-click for this specific use case. This is a rather unfortunate hack. However, #2045 is a serious problem for an important use case. Fixes #2045. --- pages/help_dialog.coffee | 10 +++++++++- pages/options.coffee | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pages/help_dialog.coffee b/pages/help_dialog.coffee index e16fd5d3..997ea915 100644 --- a/pages/help_dialog.coffee +++ b/pages/help_dialog.coffee @@ -27,11 +27,19 @@ HelpDialog = HelpDialog.toggleAdvancedCommands, false) document.documentElement.addEventListener "click", (event) => - @hide() unless @dialogElement.contains event.target + # Normally, we hide the help dialog on "click". On the options page though, we do not. This allows the + # user to view the help page while typing command names into the key mappings input; see #2045. + @hide() unless @isVimiumOptionsPage() or @dialogElement.contains event.target , false isReady: -> true + isVimiumOptionsPage: -> + try + window.top.isVimiumOptionsPage + catch + false + show: (html) -> for own placeholder, htmlString of html @dialogElement.querySelector("#help-dialog-#{placeholder}").innerHTML = htmlString diff --git a/pages/options.coffee b/pages/options.coffee index 6070400e..c708efa7 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -322,4 +322,4 @@ document.addEventListener "DOMContentLoaded", -> # Exported for tests. root = exports ? window -root.Options = Options +extend root, {Options, isVimiumOptionsPage: true} -- cgit v1.2.3 From c68b5e599607acbda54316056ad067a7aee9d251 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 27 Mar 2016 09:00:03 +0100 Subject: Fix handler return for escape. We've consumed the event here, so we should suppress it. --- content_scripts/mode_key_handler.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee index cc9ef10f..b6f384ce 100644 --- a/content_scripts/mode_key_handler.coffee +++ b/content_scripts/mode_key_handler.coffee @@ -45,7 +45,7 @@ class KeyHandlerMode extends Mode else if isEscape and HelpDialog?.showing @keydownEvents[event.keyCode] = true HelpDialog.hide() - @stopBubblingAndTrue + false # Suppress event. else if isEscape @continueBubbling else if @isMappedKey keyChar -- cgit v1.2.3