diff options
| author | mrmr1993 | 2015-06-03 04:37:45 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-06-10 17:26:53 +0100 |
| commit | ffee870176040a77e5bd541a18d1cde002cc23fa (patch) | |
| tree | d135d5e17a8c8677409b70a77b71fde69d16445a /content_scripts/mode_find.coffee | |
| parent | 32457e8dbe9ed54808738e986694c19c67c3bdd1 (diff) | |
| download | vimium-ffee870176040a77e5bd541a18d1cde002cc23fa.tar.bz2 | |
Move FindMode from vimium_frontend to mode_find
Diffstat (limited to 'content_scripts/mode_find.coffee')
| -rw-r--r-- | content_scripts/mode_find.coffee | 44 |
1 files changed, 44 insertions, 0 deletions
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 |
