Skip to content

Commit

Permalink
Fixup tree when multiselected tabs are moved together from outside of…
Browse files Browse the repository at this point in the history
… TST #3599
  • Loading branch information
piroor committed Aug 7, 2024
1 parent 5fb466a commit 2271bc9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 4 additions & 1 deletion webextensions/background/api-tabs-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,10 @@ async function onMoved(tabId, moveInfo) {
alreadyMoved,
oldPreviousTab,
oldNextTab,
isSubstantiallyMoved: movedTab.$TST.isSubstantiallyMoved
// Multiselected tabs can be moved together in bulk, by drag and drop
// in the horizontal tab bar, or addons like
// https://addons.mozilla.org/firefox/addon/move-tab-hotkeys/
movedInBulk: !maybeInternalOperation && (movedTab.$TST.multiselected || movedTab.$TST.movedInBulk),
};
log('tabs.onMoved: ', movedTab, extendedMoveInfo);

Expand Down
2 changes: 1 addition & 1 deletion webextensions/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ Tab.onTabInternallyMoved.addListener((tab, info = {}) => {
});

Tab.onMoved.addListener((tab, moveInfo) => {
if (!moveInfo.isSubstantiallyMoved)
if (moveInfo.movedInBulk)
return;
reserveToUpdateInsertionPosition([
tab,
Expand Down
4 changes: 2 additions & 2 deletions webextensions/background/handle-moved-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Tab.onMoving.addListener((tab, moveInfo) => {
!positionControlled ||
moveInfo.byInternalOperation ||
moveInfo.alreadyMoved ||
moveInfo.isSubstantiallyMoved)
!moveInfo.movedInBulk)
return true;

// if there is no valid opener, it can be a restored initial tab in a restored window
Expand Down Expand Up @@ -197,7 +197,7 @@ reserveToEnsureRootTabVisible.tabIds = new Set();

Tab.onMoved.addListener((tab, moveInfo = {}) => {
if (moveInfo.byInternalOperation ||
moveInfo.isSubstantiallyMoved ||
!moveInfo.movedInBulk ||
tab.$TST.duplicating) {
log('internal move');
}
Expand Down
13 changes: 7 additions & 6 deletions webextensions/common/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -1922,22 +1922,23 @@ export default class Tab {
this.lastNextTabId = this.unsafeNextTab?.id;
}

get isSubstantiallyMoved() {
// https://github.com/piroor/treestyletab/issues/2309#issuecomment-518583824
get movedInBulk() {
const previousTab = this.unsafePreviousTab;
if (this.lastPreviousTabId &&
this.lastPreviousTabId != previousTab?.id) {
log(`isSubstantiallyMoved lastPreviousTabId=${this.lastNextTabId}, previousTab=${previousTab?.id}`);
return true;
log(`not bulkMoved lastPreviousTabId=${this.lastNextTabId}, previousTab=${previousTab?.id}`);
return false;
}

const nextTab = this.unsafeNextTab;
if (this.lastNextTabId &&
this.lastNextTabId != nextTab?.id) {
log(`isSubstantiallyMoved lastNextTabId=${this.lastNextTabId}, nextTab=${nextTab?.id}`);
return true;
log(`not bulkMoved lastNextTabId=${this.lastNextTabId}, nextTab=${nextTab?.id}`);
return false;
}

return false;
return true;
}

get sanitized() {
Expand Down

0 comments on commit 2271bc9

Please sign in to comment.