From 1c076fbcf9d37533cc24e30476e23c050f1eda0f Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 10 Jun 2015 15:56:30 +0100 Subject: Integrate functions exposed on window into FindMode --- content_scripts/mode_find.coffee | 36 ++++++++++++++++----------------- content_scripts/mode_visual_edit.coffee | 2 +- content_scripts/vimium_frontend.coffee | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index e65450f2..4d7f3972 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -83,7 +83,7 @@ class FindMode extends Mode # 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 + query = if findModeQuery.isRegex then FindMode.getNextQueryFromRegexMatches(0) else findModeQuery.parsedQuery window.findModeQuery.hasResults = executeFind(query, { caseSensitive: !findModeQuery.ignoreCase }) # should be called whenever rawQuery is modified. @@ -132,27 +132,27 @@ class FindMode extends Mode text = document.body.innerText findModeQuery.matchCount = text.match(pattern)?.length -window.getNextQueryFromRegexMatches = (stepSize) -> - # find()ing an empty query always returns false - return "" unless findModeQuery.regexMatches + @getNextQueryFromRegexMatches: (stepSize) -> + # find()ing an empty query always returns false + return "" unless findModeQuery.regexMatches - totalMatches = findModeQuery.regexMatches.length - findModeQuery.activeRegexIndex += stepSize + totalMatches - findModeQuery.activeRegexIndex %= totalMatches + totalMatches = findModeQuery.regexMatches.length + findModeQuery.activeRegexIndex += stepSize + totalMatches + findModeQuery.activeRegexIndex %= totalMatches - findModeQuery.regexMatches[findModeQuery.activeRegexIndex] + findModeQuery.regexMatches[findModeQuery.activeRegexIndex] -window.getFindModeQuery = (backwards) -> - # check if the query has been changed by a script in another frame - mostRecentQuery = FindModeHistory.getQuery() - if (mostRecentQuery != findModeQuery.rawQuery) - findModeQuery.rawQuery = mostRecentQuery - FindMode.updateQuery() + @getQuery: (backwards) -> + # check if the query has been changed by a script in another frame + mostRecentQuery = FindModeHistory.getQuery() + if (mostRecentQuery != findModeQuery.rawQuery) + findModeQuery.rawQuery = mostRecentQuery + FindMode.updateQuery() - if findModeQuery.isRegex - getNextQueryFromRegexMatches(if backwards then -1 else 1) - else - findModeQuery.parsedQuery + if findModeQuery.isRegex + @getNextQueryFromRegexMatches(if backwards then -1 else 1) + else + findModeQuery.parsedQuery getCurrentRange = -> selection = getSelection() diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 2abccaac..e01df819 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -352,7 +352,7 @@ class Movement extends CountPrefix unless @options.parentMode or options.oneMovementOnly do => executeFind = (count, findBackwards) => - if query = getFindModeQuery findBackwards + if query = FindMode.getQuery findBackwards initialRange = @selection.getRangeAt(0).cloneRange() for [0...count] unless window.find query, Utils.hasUpperCase(query), findBackwards, true, false, true, false diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 80da43bb..a71a094e 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -679,7 +679,7 @@ selectFoundInputElement = -> findAndFocus = (backwards) -> Marks.setPreviousPosition() - query = getFindModeQuery backwards + query = FindMode.getQuery backwards window.findModeQuery.hasResults = executeFind(query, { backwards: backwards, caseSensitive: !findModeQuery.ignoreCase }) -- cgit v1.2.3