From dbccc940c0128a62ecdf1b1f88a5b2b1bf0ccfe7 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 1 Apr 2016 16:30:08 +0200 Subject: [PATCH] Improve automatic mode switching on page load Previously, Normal mode was _always_ entered on location change (page load) (unless the page is blacklisted; then Ignore mode is entered instead). There were to reasons for this: Handling the blacklist, and auto-exiting hints mode (because hints left over from another page does not make sense in a new page). However, this caused a few problems: - If you used the `zF` command while a page was loading, the markers would disappear when the page fired the "location change" event. - There was an ugly special case for Find mode, making sure not to enter Normal mode if currently in Find mode (see commit fc7e61e7c). - Sometimes, you can enter Hints mode on a newly loaded page just before the page fires the "location change" event, making hints annoyingly disappear. This commit changes two things: - Hints mode is automatically exited (by returning to Normal mode) on the 'pagehide' event instead. - The current mode is only changed on location change _if needed._ That is, to auto-exit Ignore mode after navigating away from a blacklisted page, or auto-enter Ignore mode on blacklisted pages. --- extension/lib/events-frame.coffee | 1 + extension/lib/vim.coffee | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/extension/lib/events-frame.coffee b/extension/lib/events-frame.coffee index 71e90a48..bac51084 100644 --- a/extension/lib/events-frame.coffee +++ b/extension/lib/events-frame.coffee @@ -95,6 +95,7 @@ class FrameEventManager if target == @vim.content.document messageManager.send('frameCanReceiveEvents', false) + @vim.enterMode('normal') if @vim.mode =='hints' # If the target isn’t the topmost document, it means that a frame has # changed: It could have been removed or its `src` attribute could have diff --git a/extension/lib/vim.coffee b/extension/lib/vim.coffee index 0e6d7c53..b12ec44b 100644 --- a/extension/lib/vim.coffee +++ b/extension/lib/vim.coffee @@ -33,6 +33,7 @@ ChromeWindow = Ci.nsIDOMChromeWindow class Vim constructor: (browser, @_parent) -> + @mode = undefined @focusType = 'none' @_setBrowser(browser, {addListeners: false}) @_storage = {} @@ -128,11 +129,12 @@ class Vim return suppress _onLocationChange: (url) -> - unless @mode == 'ignore' and @_storage.ignore.type == 'explicit' - if @_isBlacklisted(url) + switch + when @_isBlacklisted(url) @enterMode('ignore', {type: 'blacklist'}) - else - @enterMode('normal') unless @mode == 'find' + when (@mode == 'ignore' and @_storage.ignore.type == 'blacklist') or + not @mode + @enterMode('normal') @_parent.emit('locationChange', {vim: this, location: new @window.URL(url)}) _call: (method, data = {}, extraArgs...) ->