From d243cfc89eacbf1bc66d4fe9b234ca3d12d0717b Mon Sep 17 00:00:00 2001 From: tconfrey Date: Fri, 11 Oct 2024 18:55:38 -0400 Subject: [PATCH] fixed corner case screwing up tab ordering when tabMove came before tabJoinedTG which then had the wrong tab indicies --- app/bt.js | 12 +++++++++--- extension/background.js | 27 +++++++++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/bt.js b/app/bt.js index b8e55f4..a2f8e80 100644 --- a/app/bt.js +++ b/app/bt.js @@ -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; @@ -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; } diff --git a/extension/background.js b/extension/background.js index 03f002b..98db4ad 100644 --- a/extension/background.js +++ b/extension/background.js @@ -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); } }));