deglobalize onAttached listener for editor tabs
* bonus: one unconditional global listener less * bonus: in FF the saved window size is restored on detaching * theoretically possible drawback: 100+ editor tabs on a slow computer may be slower than before
This commit is contained in:
parent
738846a614
commit
d1924c1d63
|
@ -31,19 +31,6 @@ chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
||||||
listener('styleReplaceAll', data));
|
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) =>
|
chrome.contextMenus.onClicked.addListener((info, tab) =>
|
||||||
contextMenus[info.menuItemId].click(info, tab));
|
contextMenus[info.menuItemId].click(info, tab));
|
||||||
|
|
||||||
|
|
22
edit/edit.js
22
edit/edit.js
|
@ -476,8 +476,26 @@ queryTabs({currentWindow: true}).then(tabs => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
getActiveTab().then(tab => {
|
getOwnTab().then(tab => {
|
||||||
useHistoryBack = sessionStorageHash('manageStylesHistory').value[tab.id] === location.href;
|
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) {
|
function goBackToManage(event) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user