aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee16
1 files changed, 10 insertions, 6 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 0f6f4340..9500230b 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -266,6 +266,7 @@ class TabRecency
@timestamp = 1
@current = -1
@cache = {}
+ @removed = []
chrome.tabs.onActivated.addListener (activeInfo) => @add activeInfo.tabId
chrome.tabs.onRemoved.addListener (tabId) => @remove tabId
@@ -276,21 +277,24 @@ class TabRecency
add: (tabId) ->
@current = tabId
- @registerTabSoon tabId
+ @registerVisitSoon tabId
remove: (tabId) ->
+ @removed.push 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.
- registerTabSoon: do ->
+ # Register tabId in 500ms time, unless another tab is visited before then. Tabs which are visited only for
+ # a very-short time (e.g. those passed through with `5J`) shouldn't be registered as visited at all.
+ registerVisitSoon: do ->
timer = null
(tabId) ->
clearTimeout timer if timer
timer = setTimeout (=>
timer = null
- @cache[tabId] = ++@timestamp)
- , 750
+ # Register visit, except if tabId has already been removed (note: tab IDs are unique).
+ @cache[tabId] = ++@timestamp unless tabId in @removed
+ @removed = [])
+ , 500
# Recently-visited tabs get a higher score (except the current tab, which gets a low score).
recencyScore: (tabId) ->