aboutsummaryrefslogtreecommitdiffstats
path: root/lib/completion.js
diff options
context:
space:
mode:
authorNiklas Baumstark2012-01-25 01:21:56 +0100
committerNiklas Baumstark2012-04-10 23:57:20 +0200
commita0d0d8ecfe40a1b802f72dff100185875ee63e2f (patch)
tree4fbb645d860a1b1f9beb287d24fd4486e9c4dac2 /lib/completion.js
parentff8e8aa0e22a474b950b551259d330a7705514c3 (diff)
downloadvimium-a0d0d8ecfe40a1b802f72dff100185875ee63e2f.tar.bz2
make refresh <F5> work as expected
Diffstat (limited to 'lib/completion.js')
-rw-r--r--lib/completion.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/completion.js b/lib/completion.js
index b5793437..6aec9e83 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -104,6 +104,11 @@ var completion = (function() {
return self.matcherCache[query];
}
+ /** Clear the cache for the given source, e.g. for refreshing */
+ self.invalidateFilterCache = function(id) {
+ self.filterCache[id] = {};
+ }
+
/** Filters a collection :source using fuzzy matching against an input string :query. If a query with
* a less specific query was issued before (e.g. if the user added a letter to the query), the cached
* results of the last filtering are used as a starting point, instead of :source.
@@ -251,9 +256,6 @@ var completion = (function() {
this.extractStringFromMatch = function(match) { return stripHtmlTags(match.str); }
}
AsyncFuzzyUrlCompleter.prototype = {
- // to be implemented by subclasses
- refresh: function() { },
-
calculateRelevancy: function(query, match) {
return match.url.length /
(fuzzyMatcher.calculateRelevancy(query, this.extractStringFromMatch(match)) + 1);
@@ -279,6 +281,10 @@ var completion = (function() {
port.postMessage(query);
},
+ resetCache: function() {
+ fuzzyMatcher.invalidateFilterCache(this.id);
+ },
+
filter: function(query, callback) {
var self = this;
@@ -406,6 +412,7 @@ var completion = (function() {
}
FuzzyHistoryCompleter.prototype = new AsyncFuzzyUrlCompleter;
FuzzyHistoryCompleter.prototype.refresh = function() {
+ this.resetCache();
this.fetchFromPort('getHistory', { maxResults: this.maxResults }, function(msg) {
return msg.history.map(function(historyItem) {
return createUrlSuggestion('history', historyItem.url, historyItem.title);
@@ -419,6 +426,7 @@ var completion = (function() {
}
FuzzyBookmarkCompleter.prototype = new AsyncFuzzyUrlCompleter;
FuzzyBookmarkCompleter.prototype.refresh = function() {
+ this.resetCache();
this.fetchFromPort('getAllBookmarks', {}, function(msg) {
return msg.bookmarks.filter(function(bookmark) { return bookmark.url !== undefined })
.map(function(bookmark) {
@@ -439,6 +447,7 @@ var completion = (function() {
return [ open, open ];
}
FuzzyTabCompleter.prototype.refresh = function() {
+ this.resetCache();
this.fetchFromPort('getTabsInCurrentWindow', {}, function(msg) {
return msg.tabs.map(function(tab) {
suggestion = createUrlSuggestion('tab', tab.url, tab.title);