From a0d0d8ecfe40a1b802f72dff100185875ee63e2f Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Wed, 25 Jan 2012 01:21:56 +0100 Subject: make refresh work as expected --- lib/completion.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/completion.js') 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); -- cgit v1.2.3