diff options
| author | Phil Crosby | 2014-06-30 00:09:20 -0700 |
|---|---|---|
| committer | Phil Crosby | 2014-06-30 00:09:20 -0700 |
| commit | c235443bf2836471c6d4c2f2b58dc46d3b5e54b9 (patch) | |
| tree | e857e04b2bc312e3ce293d73dcfa40c599354add | |
| parent | c5989eb9c001429f11beff44f47adadca1784467 (diff) | |
| parent | 348a4052fed6f06e41ab84f2aa33290d20fb5a06 (diff) | |
| download | vimium-c235443bf2836471c6d4c2f2b58dc46d3b5e54b9.tar.bz2 | |
Merge pull request #1026 from mrmr1993/countMatches
Show number of matches in find HUD
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 895f9104..fdd008aa 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,18 @@ updateFindModeQuery = -> text = document.body.innerText findModeQuery.regexMatches = text.match(pattern) findModeQuery.activeRegexIndex = 0 + findModeQuery.matchCount = findModeQuery.regexMatches?.length + # if we are doing a basic plain string match, we still want to grep for matches of the string, so we can + # show a the number of results. We can grep on document.body.innerText, as it should be indistinguishable + # from the internal representation used by window.find. + else + # escape all special characters, so RegExp just parses the string 'as is'. + # Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex + escapeRegExp = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g + parsedNonRegexQuery = findModeQuery.parsedQuery.replace(escapeRegExp, (char) -> "\\" + char) + 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 +827,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)") |
