From eb2df8cb18295f629a4cd1910ec39f765474a256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Mon, 4 Nov 2024 08:45:28 +0100 Subject: [PATCH] Fix: Handle TabClose event in ZenPinnedTabManager This commit addresses a bug where the `TabClose` event was not being handled correctly by the `ZenPinnedTabManager`. This resulted in incorrect behavior when closing tabs, particularly in the context of multiple windows. The following changes were made: - The `TabClose` event is now handled explicitly within the `_onTabEvent` method. - The `_removePinnedAttributes` method is called to remove any pinned attributes associated with the closed tab. - The `_onCloseTabShortcut` method is updated to use `e.target?.closest("tab")` to ensure it targets the correct tab element. This fix ensures that pinned tab attributes are properly removed when a tab is closed, preventing unexpected behavior and data inconsistencies. --- src/ZenPinnedTabManager.mjs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ZenPinnedTabManager.mjs b/src/ZenPinnedTabManager.mjs index c626bfd..e163a4d 100644 --- a/src/ZenPinnedTabManager.mjs +++ b/src/ZenPinnedTabManager.mjs @@ -178,10 +178,9 @@ delete tab._zenClickEventListener; } break; - // TODO: Do this in a better way. Closing a second window could trigger remove tab and delete it from db - // case "TabClose": - // this._removePinnedAttributes(tab); - // break; + case "TabClose": + this._removePinnedAttributes(tab); + break; default: console.warn('ZenPinnedTabManager: Unhandled tab event', action); break; @@ -189,8 +188,8 @@ } _onTabClick(e) { - const tab = e.target; - if (e.button === 1) { + const tab = e.target?.closest("tab"); + if (e.button === 1 && tab) { this._onCloseTabShortcut(e, tab); } } @@ -393,7 +392,7 @@ const element = window.MozXULElement.parseXULToFragment(`