diff options
| -rw-r--r-- | fuzzyMode.js | 1 | ||||
| -rw-r--r-- | lib/completion.js | 15 |
2 files changed, 13 insertions, 3 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js index 87b4470a..8d8f1412 100644 --- a/fuzzyMode.js +++ b/fuzzyMode.js @@ -119,6 +119,7 @@ var fuzzyMode = (function() { // refresh with F5 else if (keyChar == 'f5') { this.completer.refresh(); + this.lastQuery = null; this.update(); } 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); |
