diff options
| author | Stephen Blott | 2015-02-23 13:32:20 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2015-02-23 13:32:20 +0000 | 
| commit | 7e0af264d7c50f7fe50dc086bde1011330d3be9a (patch) | |
| tree | a53d7fe4c16e35fe9d5b91b374173520148ea0a5 | |
| parent | b256d8463df4a68b096bf784c9f56899a7b7e57c (diff) | |
| download | vimium-7e0af264d7c50f7fe50dc086bde1011330d3be9a.tar.bz2 | |
Find (from visual mode) returns to viewport on no match.
The intention here is that, under visual mode, a find query with no
matches leaves us at some aribtrary place in the page.  Whereas the user
was probably looking at the text they're interested in in the viewport
to begin with.  This PR returns to the original viewport in such cases.
(In this commit, return-to-viewport is enabled for *all* finds, not just
under visual mode.  I want to try it out like this to see what it feels
like.  This is probably not the right UX.  It is not what Chrome does.)
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 2 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 15 | 
2 files changed, 11 insertions, 6 deletions
| diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index a5758a64..26076123 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -361,7 +361,7 @@ class Movement extends CountPrefix          @movements.n = (count) -> executeFind count, false          @movements.N = (count) -> executeFind count, true          @movements["/"] = -> -          @findMode = window.enterFindMode() +          @findMode = window.enterFindMode returnToViewport: true            @findMode.onExit => @changeMode VisualMode      #      # End of Movement constructor. diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 78901113..b2590edb 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -723,9 +723,11 @@ handleEnterForFindMode = ->    FindModeHistory.saveQuery findModeQuery.rawQuery  class FindMode extends Mode -  constructor: -> +  constructor: (options = {}) ->      @historyIndex = -1      @partialQuery = "" +    @scrollX = window.scrollX +    @scrollY = window.scrollY      super        name: "find"        badge: "/" @@ -755,10 +757,12 @@ class FindMode extends Mode            DomUtils.suppressPropagation(event)            handlerStack.stopBubblingAndFalse -      keypress: (event) -> -        handlerStack.neverContinueBubbling -> +      keypress: (event) => +        handlerStack.neverContinueBubbling =>            if event.keyCode > 31              keyChar = String.fromCharCode event.charCode +            # Primarily for visual mode. If there's no match, we return to the original viewport. +            window.scrollTo @scrollX, @scrollY if options.returnToViewport              handleKeyCharForFindMode keyChar if keyChar        keyup: (event) => @suppressEvent @@ -990,12 +994,13 @@ findModeRestoreSelection = (range = findModeInitialRange) ->    selection.addRange range  # Enters find mode.  Returns the new find-mode instance. -window.enterFindMode = -> +# Experimental.  Try "returnToViewport: true" for *all* find operations. +window.enterFindMode = (options = { returnToViewport: true }) ->    # Save the selection, so performFindInPlace can restore it.    findModeSaveSelection()    findModeQuery = { rawQuery: "" }    HUD.show("/") -  new FindMode() +  new FindMode options  exitFindMode = ->    HUD.hide() | 
