diff options
| author | Stephen Blott | 2014-11-18 16:55:27 +0000 |
|---|---|---|
| committer | Stephen Blott | 2014-11-18 16:55:27 +0000 |
| commit | a1e95718b9713c60d8c7a84e8b7c86590e3ffc7b (patch) | |
| tree | 543c65083c04369ac0f2ff81d1b8a145db2e597b | |
| parent | 4c2be63d8591d8b254eed918cebf9fb36e9b5597 (diff) | |
| download | vimium-a1e95718b9713c60d8c7a84e8b7c86590e3ffc7b.tar.bz2 | |
Tabs recency; always choose correct current tab.
| -rw-r--r-- | background_scripts/completion.coffee | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index d750850f..0f6f4340 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -264,6 +264,7 @@ class DomainCompleter class TabRecency constructor: -> @timestamp = 1 + @current = -1 @cache = {} chrome.tabs.onActivated.addListener (activeInfo) => @add activeInfo.tabId @@ -273,24 +274,28 @@ class TabRecency @remove removedTabId @add addedTabId - add: (tabId) -> @soon => @cache[tabId] = ++@timestamp - remove: (tabId) -> delete @cache[tabId] + add: (tabId) -> + @current = tabId + @registerTabSoon tabId + + 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 -> + registerTabSoon: do -> timer = null - (callback) -> + (tabId) -> clearTimeout timer if timer - timer = setTimeout (-> + timer = setTimeout (=> timer = null - callback()) + @cache[tabId] = ++@timestamp) , 750 # Recently-visited tabs get a higher score (except the current tab, which gets a low score). recencyScore: (tabId) -> @cache[tabId] ||= 1 - if @cache[tabId] == @timestamp then 0.0 else @cache[tabId] / @timestamp + if tabId == @current then 0.0 else @cache[tabId] / @timestamp tabRecency = new TabRecency() |
