aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/vimium_frontend.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
-rw-r--r--content_scripts/vimium_frontend.coffee15
1 files changed, 10 insertions, 5 deletions
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()