diff options
| author | mrmr1993 | 2014-04-19 01:32:35 +0100 |
|---|---|---|
| committer | mrmr1993 | 2014-04-19 01:32:35 +0100 |
| commit | 712794cd60608e8d02e6cd5c982bbf73a893f0f5 (patch) | |
| tree | bfd47d369cf2557ffccb3d7c5e9c3913449d2df6 /content_scripts | |
| parent | ea9fd000fadf46bc7d53685716c3e5fe5056350a (diff) | |
| download | vimium-712794cd60608e8d02e6cd5c982bbf73a893f0f5.tar.bz2 | |
Implement number of matches in find mode
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index a2139df6..5ba6fa45 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -8,7 +8,7 @@ window.handlerStack = new HandlerStack insertModeLock = null findMode = false -findModeQuery = { rawQuery: "" } +findModeQuery = { rawQuery: "", matchCount: 0 } findModeQueryHasResults = false findModeAnchorNode = null isShowingHelpDialog = false @@ -554,6 +554,25 @@ updateFindModeQuery = -> text = document.body.innerText findModeQuery.regexMatches = text.match(pattern) findModeQuery.activeRegexIndex = 0 + findModeQuery.matchCount = findModeQuery.regexMatches?.length + else + # escape all special characters, so RegExp just parses the string + parsedNonRegexQuery = findModeQuery.parsedQuery.replace("\\", "\\\\") + .replace("^", "\\^") + .replace("$", "\\$") + .replace("*", "\\*") + .replace("+", "\\+") + .replace("?", "\\?") + .replace("(", "\\(") + .replace(")", "\\)") + .replace("|", "\\|") + .replace("{", "\\{") + .replace("}", "\\}") + .replace("[", "\\[") + .replace("]", "\\]") + pattern = new RegExp(parsedNonRegexQuery, "g" + (if findModeQuery.ignoreCase then "i" else "")) + text = document.body.innerText + findModeQuery.matchCount = text.match(pattern)?.length handleKeyCharForFindMode = (keyChar) -> findModeQuery.rawQuery += keyChar @@ -815,7 +834,7 @@ window.goNext = -> showFindModeHUDForQuery = -> if (findModeQueryHasResults || findModeQuery.parsedQuery.length == 0) - HUD.show("/" + findModeQuery.rawQuery) + HUD.show("/" + findModeQuery.rawQuery + " (" + findModeQuery.matchCount + " Matches)") else HUD.show("/" + findModeQuery.rawQuery + " (No Matches)") @@ -839,7 +858,7 @@ window.showHelpDialog = (html, fid) -> container.innerHTML = html container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false) - + VimiumHelpDialog = # This setting is pulled out of local storage. It's false by default. getShowAdvancedCommands: -> settings.get("helpDialog_showAdvancedCommands") |
