From ffee870176040a77e5bd541a18d1cde002cc23fa Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 3 Jun 2015 04:37:45 +0100 Subject: Move FindMode from vimium_frontend to mode_find --- content_scripts/mode_find.coffee | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'content_scripts/mode_find.coffee') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index ed08fbd5..2c4fea2a 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -54,5 +54,49 @@ class PostFindMode extends SuppressPrintable handlerStack.remove() @continueBubbling +class FindMode extends Mode + constructor: (@options = {}) -> + # Save the selection, so findInPlace can restore it. + @initialRange = getCurrentRange() + window.findModeQuery = rawQuery: "" + if @options.returnToViewport + @scrollX = window.scrollX + @scrollY = window.scrollY + super + name: "find" + indicator: false + exitOnClick: true + + HUD.showFindMode() + + exit: (event) -> + super() + handleEscapeForFindMode() if event + + restoreSelection: -> + range = @initialRange + selection = getSelection() + selection.removeAllRanges() + selection.addRange range + + findInPlace: -> + # 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. + @restoreSelection() + query = if findModeQuery.isRegex then getNextQueryFromRegexMatches(0) else findModeQuery.parsedQuery + window.findModeQueryHasResults = executeFind(query, { caseSensitive: !findModeQuery.ignoreCase }) + +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 + root = exports ? window root.PostFindMode = PostFindMode +root.FindMode = FindMode -- cgit v1.2.3