From 15ca22e6e2d4796ea0677e237d5d4e9ff02bd4d1 Mon Sep 17 00:00:00 2001 From: ilya Date: Fri, 2 Apr 2010 15:56:35 -0700 Subject: Add more robust support for keeping track of positions/windows when tabs are moved within or between windows. --- background_page.html | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/background_page.html b/background_page.html index c78c9c2a..0e56409f 100644 --- a/background_page.html +++ b/background_page.html @@ -314,12 +314,20 @@ }); chrome.tabs.onAttached.addListener(function(tabId, attachedInfo) { - openTabs[tabId].windowId = attachedInfo.newWindowId; - openTabs[tabId].positionIndex = attachedInfo.newPosition; + // We should update all the tabs in the old window and the new window. + if (openTabs[tabId]) { + updatePositionsAndWindowsForAllTabsInWindow(openTabs[tabId].windowId); + } + updatePositionsAndWindowsForAllTabsInWindow(attachedInfo.newWindowId); + }); + + chrome.tabs.onMoved.addListener(function(tabId, moveInfo) { + updatePositionsAndWindowsForAllTabsInWindow(moveInfo.windowId); }); chrome.tabs.onRemoved.addListener(function(tabId) { var openTabInfo = openTabs[tabId]; + if (!openTabInfo) { return; } // This tab might've been opened before the extension was installed. // If we restore the new tab page, it'll ignore Vimium keystrokes when it reappears. if (openTabInfo.url == "chrome://newtab/") { return; } @@ -363,6 +371,19 @@ } // End action functions + function updatePositionsAndWindowsForAllTabsInWindow(windowId) { + chrome.tabs.getAllInWindow(windowId, function (tabs) { + for (var i = 0; i < tabs.length; i++) { + var tab = tabs[i]; + var openTabInfo = openTabs[tab.id]; + if (openTabInfo) { + openTabInfo.positionIndex = tab.index; + openTabInfo.windowId = tab.windowId; + } + } + }); + } + function splitKeyIntoFirstAndSecond(key) { if (key.search(hasModifierRegex) == 0) return { first: key.slice(0, 5), second: key.slice(5) }; -- cgit v1.2.3