aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-06-04 13:44:46 +0100
committerStephen Blott2015-06-04 13:44:50 +0100
commit5901968be865588c2444055f8e63916a22c01156 (patch)
tree411be88d94137026e2c4453461d4793691cee21e
parent01dce1cd588adc2306dd4ea02399ac9ba97372df (diff)
downloadvimium-5901968be865588c2444055f8e63916a22c01156.tar.bz2
Global marks; use chrome.tabs.query.
(As suggested by @mrmr1993 in #1716.)
-rw-r--r--background_scripts/marks.coffee22
1 files changed, 10 insertions, 12 deletions
diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee
index f599cfe3..6692dc6f 100644
--- a/background_scripts/marks.coffee
+++ b/background_scripts/marks.coffee
@@ -63,18 +63,16 @@ Marks =
# The tab we're trying to find no longer exists. We either find another tab with a matching URL and use it,
# or we create a new tab.
focusOrLaunch: (markInfo) ->
- chrome.windows.getAll { populate: true }, (windows) =>
- for window in windows
- for tab in window.tabs
- if markInfo.url == @getBaseUrl tab.url
- # We have a matching tab: use it.
- @gotoPositionInTab extend markInfo, tabId: tab.id
- return
- # There is no existing matching tab, we'll have to create one.
- chrome.tabs.create { url: @getBaseUrl markInfo.url }, (tab) =>
- # Note. tabLoadedHandlers is defined in "main.coffee". The handler below will be called when the tab
- # is loaded, its DOM is ready and it registers with the background page.
- tabLoadedHandlers[tab.id] = => @gotoPositionInTab extend markInfo, tabId: tab.id
+ chrome.tabs.query { url: markInfo.url }, (tabs) =>
+ if 0 < tabs.length
+ # We have a matching tab: use it.
+ @gotoPositionInTab extend markInfo, tabId: tabs[0].id
+ else
+ # There is no existing matching tab, we'll have to create one.
+ chrome.tabs.create { url: @getBaseUrl markInfo.url }, (tab) =>
+ # Note. tabLoadedHandlers is defined in "main.coffee". The handler below will be called when the tab
+ # is loaded, its DOM is ready and it registers with the background page.
+ tabLoadedHandlers[tab.id] = => @gotoPositionInTab extend markInfo, tabId: tab.id
root = exports ? window
root.Marks = Marks