From 2962e14107883d356cb87cececbe26572680f544 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 23 Jan 2016 19:31:37 +0100 Subject: [PATCH] Remove hints and help on shutdown Previously, if you disabled VimFx by using the `f` command to click VimFx's "Disable" button in the Add-ons Manager, the hint markers would be left behind (though losing their styling). This meant that the entire page would be covered by a transparent element impossible to remove (other than closing the tab) and impossible to click through. A similar thing happened if you left the help dialog open in another tab while disabling VimFx. This commit makes sure that both those pieces of UI are removed on shutdown. --- extension/lib/help.coffee | 6 ++++++ extension/lib/hints.coffee | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/extension/lib/help.coffee b/extension/lib/help.coffee index ebf6dcc..d8b5523 100644 --- a/extension/lib/help.coffee +++ b/extension/lib/help.coffee @@ -28,6 +28,8 @@ SEARCH_MATCH_CLASS = 'search-match' SEARCH_NON_MATCH_CLASS = 'search-non-match' SEARCH_HIGHLIGHT_CLASS = 'search-highlight' +shutdownHandlerAdded = false + injectHelp = (window, vimfx) -> removeHelp(window) @@ -68,6 +70,10 @@ injectHelp = (window, vimfx) -> # Uncomment this line if you want to use `gulp help.html`! # utils.writeToClipboard(container.outerHTML) + unless shutdownHandlerAdded + module.onShutdown(removeHelp.bind(null, window)) + shutdownHandlerAdded = true + removeHelp = (window) -> getHelp(window)?.remove() getHelp = (window) -> window.document.getElementById(CONTAINER_ID) diff --git a/extension/lib/hints.coffee b/extension/lib/hints.coffee index 3b4ee6d..624a7ba 100644 --- a/extension/lib/hints.coffee +++ b/extension/lib/hints.coffee @@ -25,7 +25,6 @@ huffman = require('n-ary-huffman') {Marker} = require('./marker') utils = require('./utils') - try # TODO: Only use this path when Firefox 44 is released. {devtools} = Cu.import('resource://devtools/shared/Loader.jsm', {}) @@ -37,6 +36,8 @@ CONTAINER_ID = 'VimFxMarkersContainer' Element = Ci.nsIDOMElement XULDocument = Ci.nsIDOMXULDocument +shutdownHandlerAdded = false + # For some time we used to return the hints container from `injectHints`, and # use that reference to remove the hints when needed. That’s fine in theory, but # in case anything breaks we might loose that reference and end up with @@ -133,6 +134,10 @@ injectHints = (window, wrappers, viewport, options) -> # marker.coffee). marker.setPosition(viewport, zoom) + unless shutdownHandlerAdded + module.onShutdown(removeHints.bind(null, window)) + shutdownHandlerAdded = true + return {markers, markerMap} getMarkableElementsAndViewport = (window, filter) -> -- 2.39.3