From 9cd460d62023449476e770530bb2c961ae63b182 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 5 Jun 2016 19:01:02 +0200 Subject: [PATCH] Make the `?` command and the button _toggle_ help I've noticed people (including myself, sometimes) unconsciously expecting both the `?` command and the button to _close_ the Keyboard Shortcuts dialog if it is already open. I don't think there's any need complicating the description of the `?` command and the tooltip of the button to reflect this. --- extension/lib/button.coffee | 2 +- extension/lib/commands.coffee | 2 +- extension/lib/help.coffee | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extension/lib/button.coffee b/extension/lib/button.coffee index a82fd36..e0aa491 100644 --- a/extension/lib/button.coffee +++ b/extension/lib/button.coffee @@ -39,7 +39,7 @@ injectButton = (vimfx) -> return unless vim = vimfx.getCurrentVim(window) if vim.mode == 'normal' - help.injectHelp(window, vimfx) + help.toggleHelp(window, vimfx) else vim.enterMode('normal') }) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index c7487f5..fc62c9c 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -801,7 +801,7 @@ commands.reload_config_file = ({vim}) -> ) commands.help = ({vim}) -> - help.injectHelp(vim.window, vim._parent) + help.toggleHelp(vim.window, vim._parent) commands.dev = ({vim}) -> vim.window.DeveloperToolbar.show(true) # `true` to focus. diff --git a/extension/lib/help.coffee b/extension/lib/help.coffee index d59bc07..b674626 100644 --- a/extension/lib/help.coffee +++ b/extension/lib/help.coffee @@ -70,6 +70,13 @@ injectHelp = (window, vimfx) -> removeHelp = (window) -> getHelp(window)?.remove() +toggleHelp = (window, vimfx) -> + helpContainer = getHelp(window) + if helpContainer + helpContainer.remove() + else + injectHelp(window, vimfx) + getHelp = (window) -> window.document.getElementById(CONTAINER_ID) getSearchInput = (window) -> getHelp(window)?.querySelector('.search-input') @@ -184,6 +191,7 @@ search = (content, term) -> module.exports = { injectHelp removeHelp + toggleHelp getHelp getSearchInput } -- 2.39.3