diff options
Diffstat (limited to 'lib/completion.js')
| -rw-r--r-- | lib/completion.js | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/completion.js b/lib/completion.js index 6f5b0f96..68f8d4bf 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -117,8 +117,8 @@ var completion = (function() { if (!(id in self.filterCache)) self.filterCache[id] = {}; - // find the most specific list of results in the cache - var maxSpecificity = 0; + // find the most narrow list of results in the cache + var optSpecificity = source.length; var specificity; for (key in self.filterCache[id]) { if (!self.filterCache[id].hasOwnProperty(key)) @@ -130,11 +130,15 @@ var completion = (function() { continue; } + // is this a plausible result set to use as a source? + if (query.indexOf(key) < 0) + continue; + // is this cache entry the most specific so far? specificity = self.filterCache[id][key].length; - if (query.indexOf(key) == 0 && specificity > maxSpecificity) { + if (specificity < optSpecificity) { source = self.filterCache[id][key]; - maxSpecificity = specificity; + optSpecificity = specificity; } } |
