Skip to content

Commit

Permalink
Refer close parent tab behavior when a solo parent tab is dragged #3651
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 5, 2024
1 parent bad6c3c commit 7e01bc6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
10 changes: 2 additions & 8 deletions webextensions/background/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,7 @@ export async function moveTabsWithStructure(tabs, params = {}) {

let movedRoots = params.import ? [] : Tab.collectRootTabs(movedTabs);

const movedWholeTree = [].concat(movedRoots);
for (const movedRoot of movedRoots) {
const descendants = movedRoot.$TST.descendants;
for (const descendant of descendants) {
if (!movedWholeTree.includes(descendant))
movedWholeTree.push(descendant);
}
}
const movedWholeTree = Tree.getWholeTree(movedRoots);
log('=> movedTabs: ', () => ['moved', movedTabs.map(dumpTab).join(' / '), 'whole', movedWholeTree.map(dumpTab).join(' / ')]);

const movedTabsSet = new Set(movedTabs);
Expand Down Expand Up @@ -568,6 +561,7 @@ export async function moveTabsWithStructure(tabs, params = {}) {
await Tree.detachTabsFromTree(movedTabs, {
insertBefore: params.insertBefore,
insertAfter: params.insertAfter,
partial: true,
broadcast: params.broadcast,
});
}
Expand Down
27 changes: 26 additions & 1 deletion webextensions/background/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,40 @@ export function detachTab(child, options = {}) {
});
}

export function getWholeTree(rootTabs) {
if (!Array.isArray(rootTabs))
rootTabs = [rootTabs];
const wholeTree = [].concat(rootTabs);
for (const movedRoot of rootTabs) {
const descendants = movedRoot.$TST.descendants;
for (const descendant of descendants) {
if (!wholeTree.includes(descendant))
wholeTree.push(descendant);
}
}
return wholeTree;
}

export async function detachTabsFromTree(tabs, options = {}) {
if (!Array.isArray(tabs))
tabs = [tabs];
tabs = Array.from(tabs).reverse();
// you should specify this option if you already call "Tree.getWholeTree()" for the tabs.
const partial = 'partial' in options ?
options.partial :
getWholeTree(tabs).length != tabs.length;
const promisedAttach = [];
for (const tab of tabs) {
let behavior = partial ?
TreeBehavior.getParentTabOperationBehavior(tab, {
context: Constants.kPARENT_TAB_OPERATION_CONTEXT_CLOSE,
}) :
Constants.kPARENT_TAB_OPERATION_BEHAVIOR_PROMOTE_FIRST_CHILD;
if (behavior == Constants.kPARENT_TAB_OPERATION_BEHAVIOR_ENTIRE_TREE)
behavior = Constants.kPARENT_TAB_OPERATION_BEHAVIOR_PROMOTE_FIRST_CHILD;
promisedAttach.push(detachAllChildren(tab, {
...options,
behavior: Constants.kPARENT_TAB_OPERATION_BEHAVIOR_PROMOTE_FIRST_CHILD,
behavior,
ignoreTabs: tabs,
}));
}
Expand Down

0 comments on commit 7e01bc6

Please sign in to comment.