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 | |
| parent | 32457e8dbe9ed54808738e986694c19c67c3bdd1 (diff) | |
| download | vimium-ffee870176040a77e5bd541a18d1cde002cc23fa.tar.bz2 | |
Move FindMode from vimium_frontend to mode_find
| -rw-r--r-- | content_scripts/mode_find.coffee | 44 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 43 |
2 files changed, 44 insertions, 43 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 diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 820645bc..b6ca06a2 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -686,38 +686,6 @@ window.handleEnterForFindMode = -> document.body.classList.add("vimiumFindMode") FindModeHistory.saveQuery findModeQuery.rawQuery -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 }) - # :options is an optional dict. valid parameters are 'caseSensitive' and 'backwards'. window.executeFind = (query, options) -> result = null @@ -897,17 +865,6 @@ window.goNext = -> nextStrings = nextPatterns.split(",").filter( (s) -> s.trim().length ) findAndFollowRel("next") || findAndFollowLink(nextStrings) -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 - # Enters find mode. Returns the new find-mode instance. window.enterFindMode = -> Marks.setPreviousPosition() |
