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/completion.coffee') 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 From a1e95718b9713c60d8c7a84e8b7c86590e3ffc7b Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 18 Nov 2014 16:55:27 +0000 Subject: Tabs recency; always choose correct current tab. --- background_scripts/completion.coffee | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'background_scripts/completion.coffee') 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() -- cgit v1.2.3 From fd92fc16878c78c0183e7d6c1df2fbbcb7b1b6e2 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 18 Nov 2014 18:43:04 +0000 Subject: Tab recency; eliminate potential memory leak. --- background_scripts/completion.coffee | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'background_scripts/completion.coffee') 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) -> -- cgit v1.2.3 From 6d87d0a123d0ea142d8c1b0a959b037f79f5ddb6 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sat, 22 Nov 2014 13:24:26 +0000 Subject: Make delayed tab registration synchronous, real-time-based --- background_scripts/completion.coffee | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 9500230b..8efd1687 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -262,12 +262,16 @@ class DomainCompleter # 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 - @current = -1 - @cache = {} - @removed = [] + timestamp: 1 + current: -1 + cache: {} + + lastVisited: null + lastVisitedTime: null + + timeDelta: 500 + constructor: -> chrome.tabs.onActivated.addListener (activeInfo) => @add activeInfo.tabId chrome.tabs.onRemoved.addListener (tabId) => @remove tabId @@ -276,26 +280,24 @@ class TabRecency @add addedTabId add: (tabId) -> + currentTime = new Date() + # Register tabId if it has been visited for at least @timeDelta. 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. + if @lastVisitedTime? and currentTime - @lastVisitedTime >= @timeDelta + @cache[@lastVisited] = ++@timestamp + @current = tabId - @registerVisitSoon tabId + @lastVisited = tabId + # If the tab we were previously on has gone away (or never existed if this is the first tab), then make + # this one registers as soon as it's blurred. + @lastVisitedTime = if @lastVisitedTime? then currentTime else new Date(currentTime - @timeDelta) remove: (tabId) -> - @removed.push tabId + if tabId == @lastVisited + # Ensure we don't register this tab, since it's going away. + @lastVisited = @lastVisitedTime = null delete @cache[tabId] - # 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 - # 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) -> @cache[tabId] ||= 1 -- cgit v1.2.3 From 24486c68d96f25030ecb97535647f78a7d9355a6 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sat, 22 Nov 2014 14:50:52 +0000 Subject: Merge two assignments of the same value --- background_scripts/completion.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 8efd1687..8883221a 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -286,8 +286,7 @@ class TabRecency if @lastVisitedTime? and currentTime - @lastVisitedTime >= @timeDelta @cache[@lastVisited] = ++@timestamp - @current = tabId - @lastVisited = tabId + @current = @lastVisited = tabId # If the tab we were previously on has gone away (or never existed if this is the first tab), then make # this one registers as soon as it's blurred. @lastVisitedTime = if @lastVisitedTime? then currentTime else new Date(currentTime - @timeDelta) -- cgit v1.2.3 From 5534830b0578e4ae28c637505a1a29d22da17fbd Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sat, 22 Nov 2014 14:52:59 +0000 Subject: Stop registering tabs active for <500ms in special circumstances --- background_scripts/completion.coffee | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 8883221a..dc24ebb7 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -287,9 +287,7 @@ class TabRecency @cache[@lastVisited] = ++@timestamp @current = @lastVisited = tabId - # If the tab we were previously on has gone away (or never existed if this is the first tab), then make - # this one registers as soon as it's blurred. - @lastVisitedTime = if @lastVisitedTime? then currentTime else new Date(currentTime - @timeDelta) + @lastVisitedTime = currentTime remove: (tabId) -> if tabId == @lastVisited -- cgit v1.2.3 From 1c2730ca195fcc075fbfc8bc8993672ae978b246 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 22 Nov 2014 15:16:35 +0000 Subject: Touch up tab recency. --- background_scripts/completion.coffee | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index dc24ebb7..dc5519d5 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -265,31 +265,29 @@ class TabRecency timestamp: 1 current: -1 cache: {} - lastVisited: null lastVisitedTime: null - - timeDelta: 500 + timeDelta: 500 # Milliseconds. constructor: -> - chrome.tabs.onActivated.addListener (activeInfo) => @add activeInfo.tabId - chrome.tabs.onRemoved.addListener (tabId) => @remove tabId + chrome.tabs.onActivated.addListener (activeInfo) => @register activeInfo.tabId + chrome.tabs.onRemoved.addListener (tabId) => @deregister tabId chrome.tabs.onReplaced.addListener (addedTabId, removedTabId) => - @remove removedTabId - @add addedTabId + @deregister removedTabId + @register addedTabId - add: (tabId) -> + register: (tabId) -> currentTime = new Date() - # Register tabId if it has been visited for at least @timeDelta. 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. - if @lastVisitedTime? and currentTime - @lastVisitedTime >= @timeDelta + # Register tabId if it has been visited for at least @timeDelta ms. Tabs which are visited only for a + # very-short time (e.g. those passed through with `5J`) aren't registered as visited at all. + if @lastVisitedTime? and @timeDelta <= currentTime - @lastVisitedTime @cache[@lastVisited] = ++@timestamp @current = @lastVisited = tabId @lastVisitedTime = currentTime - remove: (tabId) -> + deregister: (tabId) -> if tabId == @lastVisited # Ensure we don't register this tab, since it's going away. @lastVisited = @lastVisitedTime = null -- cgit v1.2.3