diff --git a/background/background.js b/background/background.js index 3e800ec6..0f7977a2 100644 --- a/background/background.js +++ b/background/background.js @@ -31,19 +31,6 @@ chrome.runtime.onMessage.addListener(onRuntimeMessage); listener('styleReplaceAll', data)); } -chrome.tabs.onAttached.addListener(tabId => { - // When an edit page gets attached or detached, remember its state - // so we can do the same to the next one to open. - chrome.tabs.get(tabId, tab => { - if (tab.url.startsWith(URLS.ownOrigin + 'edit.html')) { - chrome.windows.get(tab.windowId, {populate: true}, win => { - // If there's only one tab in this window, it's been dragged to new window - prefs.set('openEditInWindow', win.tabs.length === 1); - }); - } - }); -}); - chrome.contextMenus.onClicked.addListener((info, tab) => contextMenus[info.menuItemId].click(info, tab)); diff --git a/edit/edit.js b/edit/edit.js index b156e774..1915f964 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -476,8 +476,26 @@ queryTabs({currentWindow: true}).then(tabs => { }); }); -getActiveTab().then(tab => { - useHistoryBack = sessionStorageHash('manageStylesHistory').value[tab.id] === location.href; +getOwnTab().then(tab => { + const ownTabId = tab.id; + useHistoryBack = sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href; + // When an edit page gets attached or detached, remember its state + // so we can do the same to the next one to open. + chrome.tabs.onAttached.addListener(tabId => { + if (tabId === ownTabId) { + chrome.tabs.get(tabId, tab => { + chrome.windows.get(tab.windowId, {populate: true}, win => { + // If there's only one tab in this window, it's been dragged to new window + const openEditInWindow = win.tabs.length === 1; + if (openEditInWindow && FIREFOX) { + // FF-only because Chrome retardedly resets the size during dragging + chrome.windows.update(tab.windowId, prefs.get('windowPosition')); + } + prefs.set('openEditInWindow', openEditInWindow); + }); + }); + } + }); }); function goBackToManage(event) {