diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | background_scripts/completion.coffee | 4 | ||||
| -rw-r--r-- | content_scripts/mode_find.coffee | 43 | ||||
| -rw-r--r-- | content_scripts/ui_component.coffee | 2 | ||||
| -rw-r--r-- | lib/utils.coffee | 6 | ||||
| -rw-r--r-- | manifest.json | 2 |
6 files changed, 31 insertions, 28 deletions
@@ -153,7 +153,7 @@ Please see [CONTRIBUTING.md](https://github.com/philc/vimium/blob/master/CONTRIB Release Notes ------------- -Updates since 1.52 (not yet released) +1.53 (2015-09-25) - Vimium now works on the new-tab page for Chrome 47. - `g0` and `g$` now accept count prefixes; so `2g0` selects the second tab, and so on. diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index fb5a6120..2427bad8 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -762,8 +762,6 @@ RegexpCache = init: -> @initialized = true @clear() - # Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex - @escapeRegExp ||= /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g clear: -> @cache = {} @@ -777,7 +775,7 @@ RegexpCache = # TODO: `prefix` and `suffix` might be useful in richer word-relevancy scoring. get: (string, prefix="", suffix="") -> @init() unless @initialized - regexpString = string.replace(@escapeRegExp, "\\$&") + regexpString = Utils.escapeRegexSpecialCharacters string # Avoid cost of constructing new strings if prefix/suffix are empty (which is expected to be a common case). regexpString = prefix + regexpString if prefix regexpString = regexpString + suffix if suffix diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 9b47cfbd..e863b553 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -115,30 +115,27 @@ class FindMode extends Mode # default to 'smartcase' mode, unless noIgnoreCase is explicitly specified @query.ignoreCase = !hasNoIgnoreCaseFlag && !Utils.hasUpperCase(@query.parsedQuery) - # if we are dealing with a regex, grep for all matches in the text, and then call window.find() on them - # sequentially so the browser handles the scrolling / text selection. - if @query.isRegex - try - pattern = new RegExp(@query.parsedQuery, "g" + (if @query.ignoreCase then "i" else "")) - catch error - # if we catch a SyntaxError, assume the user is not done typing yet and return quietly - return - # innerText will not return the text of hidden elements, and strip out tags while preserving newlines - text = document.body.innerText - @query.regexMatches = text.match(pattern) - @query.activeRegexIndex = 0 - @query.matchCount = @query.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. + regexPattern = if @query.isRegex + @query.parsedQuery 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 = @query.parsedQuery.replace(escapeRegExp, (char) -> "\\" + char) - pattern = new RegExp(parsedNonRegexQuery, "g" + (if @query.ignoreCase then "i" else "")) - text = document.body.innerText - @query.matchCount = text.match(pattern)?.length + Utils.escapeRegexSpecialCharacters @query.parsedQuery + + # If we are dealing with a regex, grep for all matches in the text, and then call window.find() on them + # sequentially so the browser handles the scrolling / text selection. + # 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. + try + pattern = new RegExp regexPattern, "g#{if @query.ignoreCase then "i" else ""}" + catch error + return # If we catch a SyntaxError, assume the user is not done typing yet and return quietly. + + # innerText will not return the text of hidden elements, and strip out tags while preserving newlines. + # NOTE(mrmr1993): innerText doesn't include the text contents of <input>s and <textarea>s. See #1118. + text = document.body.innerText + regexMatches = text.match pattern + @query.regexMatches = regexMatches if @query.isRegex + @query.activeRegexIndex = 0 if @query.isRegex + @query.matchCount = regexMatches?.length @getNextQueryFromRegexMatches: (stepSize) -> # find()ing an empty query always returns false diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 72627f69..74b58b82 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -12,6 +12,8 @@ class UIComponent # Default to everything hidden while the stylesheet loads. styleSheet.innerHTML = "iframe {display: none;}" + # Use an XMLHttpRequest, possibly via the background page, to fetch the stylesheet. This allows us to + # catch and recover from failures that we could not have caught when using CSS @include (eg. #1817). UIComponent::styleSheetGetter ?= new AsyncDataFetcher @fetchFileContents "content_scripts/vimium.css" @styleSheetGetter.use (styles) -> styleSheet.innerHTML = styles diff --git a/lib/utils.coffee b/lib/utils.coffee index 350b11a5..b69b926b 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -19,6 +19,12 @@ Utils = func = obj[components.pop()] func.apply(obj, argArray) + # Escape all special characters, so RegExp will parse the string 'as is'. + # Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex + escapeRegexSpecialCharacters: do -> + escapeRegex = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g + (str) -> str.replace escapeRegex, "\\$&" + escapeHtml: (string) -> string.replace(/</g, "<").replace(/>/g, ">") # Generates a unique ID diff --git a/manifest.json b/manifest.json index 6d971db2..acd41d12 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Vimium", - "version": "1.52", + "version": "1.53", "description": "The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", |
