record the newly open tab id if new window is craeted, which makes delete easier
This commit is contained in:
parent
84bfe683c5
commit
fd793b7195
1 changed files with 12 additions and 10 deletions
|
@ -259,27 +259,29 @@ const backgroundLogic = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async _sortTabsByWindowInternal(windowId, cookieStoreId) {
|
async _sortTabsByWindowInternal(windowId, cookieStoreId) {
|
||||||
let createNew = false;
|
let newlyOpenedTabId = null;
|
||||||
let tabs = await browser.tabs.query({
|
const tabs = await browser.tabs.query({
|
||||||
"cookieStoreId": cookieStoreId
|
"cookieStoreId": cookieStoreId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// create a new window so that move tabs to the new window
|
||||||
if (windowId === -1) {
|
if (windowId === -1) {
|
||||||
const newWindowObj = await browser.windows.create();
|
const newWindowObj = await browser.windows.create();
|
||||||
windowId = newWindowObj.id;
|
windowId = newWindowObj.id;
|
||||||
createNew = true;
|
newlyOpenedTabId = newWindowObj.tabs[0].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move all tabs
|
||||||
browser.tabs.move(tabs.map((tab) => tab.id), {
|
browser.tabs.move(tabs.map((tab) => tab.id), {
|
||||||
windowId: windowId,
|
windowId: windowId,
|
||||||
index: -1
|
index: -1
|
||||||
});
|
});
|
||||||
if (createNew) {
|
|
||||||
tabs = await browser.tabs.query({windowId: windowId});
|
// if new window is created, then close newly opened tab by its id
|
||||||
for (const tab of tabs) {
|
if (newlyOpenedTabId !== null) {
|
||||||
if (tab.cookieStoreId !== cookieStoreId) {
|
browser.tabs.remove(newlyOpenedTabId);
|
||||||
browser.tabs.remove(tab.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async sortTabs() {
|
async sortTabs() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue