From 4dc517401a2d01d34455498ff805e81f7f4f2674 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 13 Nov 2012 22:18:06 +0000 Subject: Smartcase matching for vomnibar. Vomnibar queries are case insensitive, unless the query contains a capital letter. --- background_scripts/completion.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 28bb1afa..c99a94cb 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -355,7 +355,10 @@ RegexpCache = # 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 - @cache[regexpString] ||= new RegExp(regexpString, "i") + return @cache[regexpString] if @cache[regexpString] + # Smartcase: regexp is case insensitive, unless `string` contains a capital letter. + modifier = if /[A-Z]/.test string then "" else "i" + @cache[regexpString] = new RegExp(regexpString, modifier) # Provides cached access to Chrome's history. As the user browses to new pages, we add those pages to this # history cache. -- cgit v1.2.3 From 049cf4314fc2e97e0f5b09cd8a8d066e2c04eb8a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 14 Nov 2012 05:59:21 +0000 Subject: RegexpCache: reorganise and improve tests. --- background_scripts/completion.coffee | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index c99a94cb..951d0756 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -355,10 +355,8 @@ RegexpCache = # 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 - return @cache[regexpString] if @cache[regexpString] - # Smartcase: regexp is case insensitive, unless `string` contains a capital letter. - modifier = if /[A-Z]/.test string then "" else "i" - @cache[regexpString] = new RegExp(regexpString, modifier) + # Smartcase: Regexp is case insensitive, unless `string` contains a capital letter (testing `string`, not `regexpString`). + @cache[regexpString] ||= new RegExp regexpString, (if /[A-Z]/.test string then "" else "i") # Provides cached access to Chrome's history. As the user browses to new pages, we add those pages to this # history cache. -- cgit v1.2.3