aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStephen Blott2015-05-10 08:59:14 +0100
committerStephen Blott2015-05-10 09:55:06 +0100
commit1a337a261a6dd6deffa836cbd949bb036e103f36 (patch)
tree0db259e68e86f399ff6c448eb7929e4f95569eb4 /lib
parent8d51ccbb01fe2a4e7b548cc14617a05048a8d68c (diff)
downloadvimium-1a337a261a6dd6deffa836cbd949bb036e103f36.tar.bz2
Search completion; reuse previous query.
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.coffee10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 16adc305..a1ed23c2 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -184,6 +184,16 @@ Utils =
return true if re.test string
false
+ # Calculate the length of the longest shared prefix of a list of strings.
+ longestCommonPrefix: (strings) ->
+ return 0 unless 0 < strings.length
+ strings.sort (a,b) -> a.length - b.length
+ [ shortest, strings... ] = strings
+ for ch, index in shortest.split ""
+ for str in strings
+ return index if ch != str[index]
+ return shortest.length
+
# Convenience wrapper for setTimeout (with the arguments around the other way).
setTimeout: (ms, func) -> setTimeout func, ms