Skip to content

Commit

Permalink
fixed corner case screwing up tab ordering when tabMove came before t…
Browse files Browse the repository at this point in the history
…abJoinedTG which then had the wrong tab indicies
  • Loading branch information
tconfrey committed Oct 11, 2024
1 parent b26b31f commit d243cfc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
12 changes: 9 additions & 3 deletions app/bt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,8 @@ function tabJoinedTG(data) {
// settings toggle => update parent w tg info
const tgParent = AllNodes[tabNode.parentId];
tabNode.windowId = winId;
tabNode.tabGroupId = tgId;
tabNode.pendingDeletion = false;
tgParent.tabGroupId = tgId;
tgParent.windowId = winId;
return;
Expand All @@ -1116,20 +1118,24 @@ function tabJoinedTG(data) {
return;
}

// remaining option - tab moved between TGs
// remaining option - tab moved within or between TGs
tabNode.pendingDeletion = false; // no longer pending deletion
tabNode.tabGroupId = tgId;
positionInTopic(topicNode, tabNode, index, indices, winId);
// if topicNode has multiple open children then redo positioning
if (topicNode.hasOpenChildren() > 1)
positionInTopic(topicNode, tabNode, index, indices, winId);
}

function tabLeftTG(data) {
// user moved tab out of TG => no longer managed => mark for deletion
// NB don't delete cos might be moving to another TG or its TG might be moving between windows
// Also NB this may arrive after tab has already been moved to another TG, in which case don't mark for deletion

if (GroupingMode != 'TABGROUP') return;
const tabId = data.tabId;
const tabNode = BTAppNode.findFromTab(tabId);
if (!tabNode) return;
const groupId = data.groupId;
if (!tabNode || (tabNode.groupId && (tabNode.groupId != groupId))) return;
tabNode.pendingDeletion = true;
}

Expand Down
27 changes: 19 additions & 8 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,25 @@ chrome.tabs.onUpdated.addListener(logEventWrapper("tabs.onUpdated", async (tabId
}
if (changeInfo.groupId && (tab.status == 'complete') && tab.url) {
// tab moved to/from TG, wait til loaded so url etc is filled in
// Adding a delay to allow potential tab closed event to be processed first, otherwise tabLeftTG deletes BT Node
setTimeout(async () => {
btSendMessage(
BTTab, {'function': (tab.groupId > 0) ? 'tabJoinedTG' : 'tabLeftTG',
'tabId': tabId, 'groupId': tab.groupId,
'tabIndex': tab.index, 'windowId': tab.windowId, 'indices': indices,
'tab': tab});
}, 250);
const message = {
'function': (tab.groupId > 0) ? 'tabJoinedTG' : 'tabLeftTG',
'tabId': tabId,
'groupId': tab.groupId,
'tabIndex': tab.index,
'windowId': tab.windowId,
'indices': indices,
'tab': tab
};

// Adding a delay on Left to allow potential tab closed event to be processed first, otherwise tabLeftTG deletes BT Node
if (tab.groupId > 0) {
btSendMessage(BTTab, message);
} else {
setTimeout(async () => {
btSendMessage(BTTab, message);
}, 250);
}

setTimeout(function() {setBadge(tabId);}, 200);
}
}));
Expand Down

0 comments on commit d243cfc

Please sign in to comment.