diff options
| author | Stephen Blott | 2015-06-04 14:57:24 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-06-04 14:57:24 +0100 | 
| commit | fea6e507761e6870d9c240d0718cb96711891a3a (patch) | |
| tree | 966117b6af06ac3e00308d881bf4fe9de3c64715 /background_scripts | |
| parent | 5901968be865588c2444055f8e63916a22c01156 (diff) | |
| download | vimium-fea6e507761e6870d9c240d0718cb96711891a3a.tar.bz2 | |
Global marks; prefer to re-use a tab in the current window.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/marks.coffee | 12 | 
1 files changed, 10 insertions, 2 deletions
| diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee index 6692dc6f..45697ac4 100644 --- a/background_scripts/marks.coffee +++ b/background_scripts/marks.coffee @@ -65,8 +65,9 @@ Marks =    focusOrLaunch: (markInfo) ->      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 +        # We have a matching tab: use it (prefering, if there are more than one, one in the current window). +        @pickTabInWindow tabs, (tab) => +          @gotoPositionInTab extend markInfo, tabId: tab.id        else          # There is no existing matching tab, we'll have to create one.          chrome.tabs.create { url: @getBaseUrl markInfo.url }, (tab) => @@ -74,5 +75,12 @@ Marks =            # is loaded, its DOM is ready and it registers with the background page.            tabLoadedHandlers[tab.id] = => @gotoPositionInTab extend markInfo, tabId: tab.id +  # Given a list of tabs, pick one in the current window, if possible, otherwise just pick any. +  pickTabInWindow: (tabs, continuation) -> +    chrome.windows.getCurrent ({ id }) -> +      tabsInWindow = tabs.filter (tab) -> tab.windowId == id +      continuation tabsInWindow[0] ? tabs[0] + +  root = exports ? window  root.Marks = Marks | 
