From 7e0af264d7c50f7fe50dc086bde1011330d3be9a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 23 Feb 2015 13:32:20 +0000 Subject: 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.) --- content_scripts/mode_visual_edit.coffee | 2 +- content_scripts/vimium_frontend.coffee | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'content_scripts') 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() -- cgit v1.2.3