aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-18 10:45:58 +0000
committerStephen Blott2015-01-18 10:45:58 +0000
commitf484718185675bd80eb005f39dd7bdbbdfd497fa (patch)
tree8d005f3d77e7aad09fefc16970d6ae5d061cd0ec
parenta1edae57e2847c2b6ffcae60ea8c9c16216e4692 (diff)
parentf24752c8224425075129f9f10ac79bf081619722 (diff)
downloadvimium-f484718185675bd80eb005f39dd7bdbbdfd497fa.tar.bz2
Merge pull request #1434 from smblott-github/perform-find-in-place
Fix slightly wonky perform-find-in-place
-rw-r--r--content_scripts/vimium_frontend.coffee37
1 files changed, 25 insertions, 12 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 7121569a..35d92f3c 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -10,6 +10,7 @@ findMode = false
findModeQuery = { rawQuery: "", matchCount: 0 }
findModeQueryHasResults = false
findModeAnchorNode = null
+findModeInitialRange = null
isShowingHelpDialog = false
keyPort = null
# Users can disable Vimium on URL patterns via the settings page. The following two variables
@@ -771,19 +772,10 @@ class FindMode extends Mode
new PostFindMode
performFindInPlace = ->
- cachedScrollX = window.scrollX
- cachedScrollY = window.scrollY
-
+ # Restore the selection. That way, we're always searching forward from the same place, so we find the right
+ # match as the user adds matching characters, or removes previously-matched characters. See #1434.
+ findModeRestoreSelection()
query = if findModeQuery.isRegex then getNextQueryFromRegexMatches(0) else findModeQuery.parsedQuery
-
- # Search backwards first to "free up" the current word as eligible for the real forward search. This allows
- # us to search in place without jumping around between matches as the query grows.
- executeFind(query, { backwards: true, caseSensitive: !findModeQuery.ignoreCase })
-
- # We need to restore the scroll position because we might've lost the right position by searching
- # backwards.
- window.scrollTo(cachedScrollX, cachedScrollY)
-
findModeQueryHasResults = executeFind(query, { caseSensitive: !findModeQuery.ignoreCase })
# :options is an optional dict. valid parameters are 'caseSensitive' and 'backwards'.
@@ -976,7 +968,28 @@ showFindModeHUDForQuery = ->
else
HUD.show("/" + findModeQuery.rawQuery + " (No Matches)")
+getCurrentRange = ->
+ selection = getSelection()
+ if selection.type == "None"
+ range = document.createRange()
+ range.setStart document.body, 0
+ range.setEnd document.body, 0
+ range
+ else
+ selection.collapseToStart() if selection.type == "Range"
+ selection.getRangeAt 0
+
+findModeSaveSelection = ->
+ findModeInitialRange = getCurrentRange()
+
+findModeRestoreSelection = (range = findModeInitialRange) ->
+ selection = getSelection()
+ selection.removeAllRanges()
+ selection.addRange range
+
window.enterFindMode = ->
+ # Save the selection, so performFindInPlace can restore it.
+ findModeSaveSelection()
findModeQuery = { rawQuery: "" }
HUD.show("/")
new FindMode()