aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/commands.coffee4
-rw-r--r--background_scripts/completion.coffee7
-rw-r--r--background_scripts/main.coffee38
3 files changed, 27 insertions, 22 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index bca1c3a4..abfbd9e2 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -321,8 +321,8 @@ commandDescriptions =
goToRoot: ["Go to root of current URL hierarchy", { passCountToFunction: true }]
# Manipulating tabs
- nextTab: ["Go one tab right", { background: true }]
- previousTab: ["Go one tab left", { background: true }]
+ nextTab: ["Go one tab right", { background: true, passCountToFunction: true }]
+ previousTab: ["Go one tab left", { background: true, passCountToFunction: true }]
firstTab: ["Go to the first tab", { background: true }]
lastTab: ["Go to the last tab", { background: true }]
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 60e5f1df..bae73b8d 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -29,6 +29,8 @@ class Suggestion
@highlightTerms = true
# @insertText is text to insert into the vomnibar input when the suggestion is selected.
@insertText = null
+ # @deDuplicate controls whether this suggestion is a candidate for deduplication.
+ @deDuplicate = true
# Other options set by individual completers include:
# - tabId (TabCompleter)
@@ -400,6 +402,7 @@ class TabCompleter
title: tab.title
relevancyFunction: @computeRelevancy
tabId: tab.id
+ deDuplicate: false
onComplete suggestions
computeRelevancy: (suggestion) ->
@@ -492,7 +495,7 @@ class SearchEngineCompleter
for url, suggestion of @previousSuggestions
continue unless RankingUtils.matches queryTerms, suggestion.title
# Reset various fields, they may not be correct wrt. the current query.
- extend suggestion, relevancy: null, html: null, highlightTerms: false, queryTerms: queryTerms
+ extend suggestion, relevancy: null, html: null, queryTerms: queryTerms
suggestion.relevancy = null
suggestion
@@ -645,7 +648,7 @@ class MultiCompleter
suggestions =
for suggestion in suggestions
url = suggestion.shortenUrl()
- continue if seenUrls[url]
+ continue if suggestion.deDuplicate and seenUrls[url]
break if count++ == @maxResults
seenUrls[url] = suggestion
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 6ee0e8e7..a13d9d98 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -268,10 +268,10 @@ BackgroundCommands =
chrome.tabs.query {active: true, currentWindow: true}, (tabs) ->
tab = tabs[0]
chrome.windows.create {tabId: tab.id, incognito: tab.incognito}
- nextTab: (callback) -> selectTab(callback, "next")
- previousTab: (callback) -> selectTab(callback, "previous")
- firstTab: (callback) -> selectTab(callback, "first")
- lastTab: (callback) -> selectTab(callback, "last")
+ nextTab: (count) -> selectTab "next", count
+ previousTab: (count) -> selectTab "previous", count
+ firstTab: -> selectTab "first"
+ lastTab: -> selectTab "last"
removeTab: (callback) ->
chrome.tabs.getSelected(null, (tab) ->
chrome.tabs.remove(tab.id)
@@ -345,21 +345,23 @@ removeTabsRelative = (direction) ->
# Selects a tab before or after the currently selected tab.
# - direction: "next", "previous", "first" or "last".
-selectTab = (callback, direction) ->
- chrome.tabs.getAllInWindow(null, (tabs) ->
+selectTab = (direction, count = 1) ->
+ chrome.tabs.getAllInWindow null, (tabs) ->
return unless tabs.length > 1
- chrome.tabs.getSelected(null, (currentTab) ->
- switch direction
- when "next"
- toSelect = tabs[(currentTab.index + 1 + tabs.length) % tabs.length]
- when "previous"
- toSelect = tabs[(currentTab.index - 1 + tabs.length) % tabs.length]
- when "first"
- toSelect = tabs[0]
- when "last"
- toSelect = tabs[tabs.length - 1]
- selectionChangedHandlers.push(callback)
- chrome.tabs.update(toSelect.id, { selected: true })))
+ chrome.tabs.getSelected null, (currentTab) ->
+ toSelect =
+ switch direction
+ when "next"
+ currentTab.index + count
+ when "previous"
+ currentTab.index - count
+ when "first"
+ 0
+ when "last"
+ tabs.length - 1
+ # Bring toSelect into the range [0,tabs.length).
+ toSelect = (toSelect + tabs.length * Math.abs count) % tabs.length
+ chrome.tabs.update tabs[toSelect].id, selected: true
updateOpenTabs = (tab, deleteFrames = false) ->
# Chrome might reuse the tab ID of a recently removed tab.