From 78f9d1017a6993ce63c907e618f2fecb59b49d2d Mon Sep 17 00:00:00 2001 From: Folyd Date: Wed, 15 Apr 2020 23:49:44 +0800 Subject: [PATCH] Omnibox add no cached query API --- extension/main.js | 2 ++ extension/omnibox.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/extension/main.js b/extension/main.js index cfe5582f..dea2b4b4 100644 --- a/extension/main.js +++ b/extension/main.js @@ -146,4 +146,6 @@ omnibox.addPrefixQueryEvent(":", { }, }); +omnibox.addNoCacheQueries("@", ":"); + window.crateSearcher = crateSearcher; \ No newline at end of file diff --git a/extension/omnibox.js b/extension/omnibox.js index eb59460e..d578c10e 100644 --- a/extension/omnibox.js +++ b/extension/omnibox.js @@ -8,6 +8,8 @@ function Omnibox(defaultSuggestion, maxSuggestionSize = 8) { // Cache the last query and result to speed up the page down. this.cachedQuery = null; this.cachedResult = null; + // A set of query which should not be cached. + this.noCacheQueries = new Set(); } Omnibox.prototype.setDefaultSuggestion = function(description, content) { @@ -58,8 +60,10 @@ Omnibox.prototype.bootstrap = function({onSearch, onFormat, onAppend, onSelected results = this.cachedResult; } else { results = this.performSearch(query); - this.cachedQuery = query; - this.cachedResult = results; + if (!this.noCacheQueries.has(query)) { + this.cachedQuery = query; + this.cachedResult = results; + } } let totalPage = Math.ceil(results.length / this.maxSuggestionSize); @@ -151,6 +155,10 @@ Omnibox.prototype.navigateToUrl = function(url, disposition) { } }; +Omnibox.prototype.addNoCacheQueries = function(...queries) { + queries.forEach(query => this.noCacheQueries.add(query)); +}; + class QueryEvent { constructor({ onSearch, onFormat, onAppend,