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(-) 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 From d0cce1e745b66079e88ab5a5392e7fee048b458e Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 18 Apr 2015 11:17:03 +0100 Subject: Only return to viewport from visual mode. When there is no find-mode match, return to the original viewport. This is a better UX in visual mode, because the text the user is searching for is often on within the viewport. (This is also more vim like. We could consider *always* working this way.) --- content_scripts/vimium_frontend.coffee | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b2590edb..f549e06d 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -726,8 +726,9 @@ class FindMode extends Mode constructor: (options = {}) -> @historyIndex = -1 @partialQuery = "" - @scrollX = window.scrollX - @scrollY = window.scrollY + if options.returnToViewport + @scrollX = window.scrollX + @scrollY = window.scrollY super name: "find" badge: "/" @@ -735,6 +736,7 @@ class FindMode extends Mode exitOnClick: true keydown: (event) => + window.scrollTo @scrollX, @scrollY if options.returnToViewport if event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey @exit() unless handleDeleteForFindMode() @suppressEvent @@ -761,8 +763,6 @@ class FindMode extends Mode 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 @@ -994,8 +994,7 @@ findModeRestoreSelection = (range = findModeInitialRange) -> selection.addRange range # Enters find mode. Returns the new find-mode instance. -# Experimental. Try "returnToViewport: true" for *all* find operations. -window.enterFindMode = (options = { returnToViewport: true }) -> +window.enterFindMode = (options = {}) -> # Save the selection, so performFindInPlace can restore it. findModeSaveSelection() findModeQuery = { rawQuery: "" } -- cgit v1.2.3