From 4c2be63d8591d8b254eed918cebf9fb36e9b5597 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 18 Nov 2014 16:19:13 +0000 Subject: Tab recency; register visit only after 750ms. --- background_scripts/completion.coffee | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'background_scripts') 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 -- cgit v1.2.3