diff --git a/src/ZenPinnedTabManager.mjs b/src/ZenPinnedTabManager.mjs
index a6e2008..3b5c5cf 100644
--- a/src/ZenPinnedTabManager.mjs
+++ b/src/ZenPinnedTabManager.mjs
@@ -2,7 +2,7 @@
const lazy = {};
class ZenPinnedTabsObserver {
- static ALL_EVENTS = ['TabPinned', 'TabUnpinned'];
+ static ALL_EVENTS = ['TabPinned', 'TabUnpinned', 'TabClose'];
#listeners = [];
@@ -47,6 +47,8 @@
this._initClosePinnedTabShortcut();
this._insertItemsIntoTabContextMenu();
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));
+
+ this._zenClickEventListener = this._onTabClick.bind(this);
}
async _refreshPinnedTabs() {
@@ -95,7 +97,7 @@
if (!pins?.length) {
// If there are no pins, we should remove any existing pinned tabs
for (let tab of gBrowser.tabs) {
- if (tab.pinned && tab.getAttribute("zen-pin-id")) {
+ if (tab.pinned && !tab.getAttribute("zen-pin-id")) {
gBrowser.removeTab(tab);
}
}
@@ -144,6 +146,7 @@
}
newTab.setAttribute("zen-pin-id", pin.uuid);
+ gBrowser.setInitialTabTitle(newTab, pin.title);
if (pin.workspaceUuid) {
newTab.setAttribute("zen-workspace-id", pin.workspaceUuid);
@@ -162,7 +165,7 @@
const tab = event.target;
switch (action) {
case "TabPinned":
- tab._zenClickEventListener = this._onTabClick.bind(this, tab);
+ tab._zenClickEventListener = this._zenClickEventListener;
tab.addEventListener("click", tab._zenClickEventListener);
this._setPinnedAttributes(tab);
break;
@@ -173,13 +176,17 @@
delete tab._zenClickEventListener;
}
break;
+ case "TabClose":
+ this._removePinnedAttributes(tab);
+ break;
default:
console.warn('ZenPinnedTabManager: Unhandled tab event', action);
break;
}
}
- _onTabClick(tab, e) {
+ _onTabClick(e) {
+ const tab = e.target;
if (e.button === 1) {
this._onCloseTabShortcut(e, tab);
}
@@ -264,18 +271,6 @@
}
}
- setPinnedTabState(tabData, tab) {
- tabData.zenPinId = tab.getAttribute("zen-pin-id");
- }
-
- updatePinnedTabForSessionRestore(tabData, tab) {
- if (tabData.zenPinId) {
- tab.setAttribute("zen-pin-id", tabData.zenPinId);
- } else {
- tab.removeAttribute("zen-pin-id");
- }
- }
-
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab) {
if (
!selectedTab?.pinned
@@ -376,6 +371,7 @@
_insertItemsIntoTabContextMenu() {
const elements = window.MozXULElement.parseXULToFragment(`
+