Skip to content

Commit

Permalink
Improve automatic mode switching on page load
Browse files Browse the repository at this point in the history
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 fc7e61e).
- 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.
  • Loading branch information
lydell committed Apr 1, 2016
1 parent 09c8b2f commit dbccc94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions extension/lib/events-frame.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions extension/lib/vim.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ChromeWindow = Ci.nsIDOMChromeWindow

class Vim
constructor: (browser, @_parent) ->
@mode = undefined
@focusType = 'none'
@_setBrowser(browser, {addListeners: false})
@_storage = {}
Expand Down Expand Up @@ -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...) ->
Expand Down

0 comments on commit dbccc94

Please sign in to comment.