diff options
| author | Stephen Blott | 2015-06-04 11:58:13 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-06-04 11:58:13 +0100 |
| commit | 278b03bd14ddad188000e87ec1f60f925f94697b (patch) | |
| tree | 77c370937f388eeb42da60d3e34d5d44388fb4bd /background_scripts | |
| parent | 931d246e59389bd3070aa03bde4fada9f2ef9700 (diff) | |
| download | vimium-278b03bd14ddad188000e87ec1f60f925f94697b.tar.bz2 | |
Global marks; find another (existing) tab if tabId has been removed.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/marks.coffee | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee index 5336e8da..05c8e579 100644 --- a/background_scripts/marks.coffee +++ b/background_scripts/marks.coffee @@ -14,7 +14,7 @@ Marks = url: sender.tab.url scrollX: req.scrollX scrollY: req.scrollY - console.log item + markName: req.markName chrome.storage.local.set item goto: (req, sender) -> @@ -32,25 +32,35 @@ Marks = @focusOrLaunch markInfo else # Check whether markInfo.tabId still exists. - { tabId, url, scrollX, scrollY } = markInfo - chrome.tabs.get tabId, (tab) => + chrome.tabs.get markInfo.tabId, (tab) => if chrome.runtime.lastError or not tab - # The tab no longer exists. + # The original tab no longer exists. @focusOrLaunch markInfo else # The original tab still exists. - chrome.tabs.update tabId, { selected: true }, -> - chrome.tabs.sendMessage tabId, - { name: "setScrollPosition", scrollX: scrollX, scrollY: scrollY }, -> - chrome.tabs.sendMessage tabId, - name: "showHUDforDuration", - text: "Jumped to global mark '#{req.markName}'." - duration: 1000 + @gotoPositionInTab markInfo + + gotoPositionInTab: ({ tabId, scrollX, scrollY, markName }) -> + chrome.tabs.update tabId, { selected: true }, -> + chrome.tabs.sendMessage tabId, + { name: "setScrollPosition", scrollX: scrollX, scrollY: scrollY }, -> + chrome.tabs.sendMessage tabId, + name: "showHUDforDuration", + text: "Jumped to global mark '#{markName}'." + duration: 1000 # The tab we're trying to find no longer exists. Either find another tab with a matching URL and use it, or # create a new tab. - focusOrLaunch: (info) -> - console.log info + focusOrLaunch: (markInfo) -> + chrome.windows.getAll { populate: true }, (windows) => + baseUrl = @getBaseUrl markInfo.url + for window in windows + for tab in window.tabs + if baseUrl == @getBaseUrl tab.url + # We have a matching tab. We'll use it. + return @gotoPositionInTab extend markInfo, tabId: tab.id + + getBaseUrl: (url) -> url.split("#")[0] root = exports ? window root.Marks = Marks |
