diff options
| -rw-r--r-- | background_scripts/completion.coffee | 16 | ||||
| -rw-r--r-- | tests/unit_tests/test_chrome_stubs.coffee | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index b411bcba..d750850f 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -259,7 +259,8 @@ class DomainCompleter # Suggestions from the Domain completer have the maximum relevancy. They should be shown first in the list. computeRelevancy: -> 1 -# TabRecency associates a logical timestamp with each tab id. +# TabRecency associates a logical timestamp with each tab id. These are used to provide an initial +# recency-based ordering in the tabs vomnibar (which allows jumping quickly between recently-visited tabs). class TabRecency constructor: -> @timestamp = 1 @@ -272,9 +273,20 @@ class TabRecency @remove removedTabId @add addedTabId - add: (tabId) -> @cache[tabId] = ++@timestamp + add: (tabId) -> @soon => @cache[tabId] = ++@timestamp remove: (tabId) -> delete @cache[tabId] + # Call callback in 750ms time; unless we're pre-empted by another call before then. The idea is that tabs + # which are visited only for a very-short time (e.g. with `3J`) shouldn't register as visited at all. + soon: do -> + timer = null + (callback) -> + clearTimeout timer if timer + timer = setTimeout (-> + timer = null + callback()) + , 750 + # Recently-visited tabs get a higher score (except the current tab, which gets a low score). recencyScore: (tabId) -> @cache[tabId] ||= 1 diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee index 80750337..396a2e55 100644 --- a/tests/unit_tests/test_chrome_stubs.coffee +++ b/tests/unit_tests/test_chrome_stubs.coffee @@ -95,3 +95,5 @@ exports.chrome = callback() if callback # Now, generate (supposedly asynchronous) notification for listeners. global.chrome.storage.onChanged.callEmpty(key) + +exports.setTimeout = (callback,timeout) -> callback() |
