Fixed reordering tabs not being correctly saved

This commit is contained in:
mr. m
2025-03-02 11:30:10 +01:00
parent fd8a56762d
commit ff25a5b432

View File

@@ -94,7 +94,7 @@
//const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id')); //const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id'));
//if (pin) { //if (pin) {
// pin.iconUrl = iconUrl; // pin.iconUrl = iconUrl;
// ZenPinnedTabsStorage.savePin(pin); // this.savePin(pin);
//} //}
} }
@@ -174,12 +174,11 @@
} }
async _initializePinnedTabs(init = false) { async _initializePinnedTabs(init = false) {
let pins = this._pinsCache; const pins = this._pinsCache;
if (!pins?.length || !init) { if (!pins?.length || !init) {
return; return;
} }
pins = pins.sort((a, b) => a.position - b.position);
const pinnedTabsByUUID = new Map(); const pinnedTabsByUUID = new Map();
const pinsToCreate = new Set(pins.map((p) => p.uuid)); const pinsToCreate = new Set(pins.map((p) => p.uuid));
@@ -340,13 +339,13 @@
tab.position = tab._tPos; tab.position = tab._tPos;
for (let otherTab of gBrowser.tabs) { for (let otherTab of gBrowser.tabs) {
if (otherTab.pinned && otherTab._tPos > tab.position) { if (otherTab.pinned) {
const actualPin = this._pinsCache.find((pin) => pin.uuid === otherTab.getAttribute('zen-pin-id')); const actualPin = this._pinsCache.find((pin) => pin.uuid === otherTab.getAttribute('zen-pin-id'));
if (!actualPin) { if (!actualPin) {
continue; continue;
} }
actualPin.position = otherTab._tPos; actualPin.position = otherTab._tPos;
await ZenPinnedTabsStorage.savePin(actualPin, false); await this.savePin(actualPin, false);
} }
} }
@@ -357,7 +356,7 @@
} }
actualPin.position = tab.position; actualPin.position = tab.position;
actualPin.isEssential = tab.hasAttribute('zen-essential'); actualPin.isEssential = tab.hasAttribute('zen-essential');
await ZenPinnedTabsStorage.savePin(actualPin); await this.savePin(actualPin);
} }
_onTabClick(e) { _onTabClick(e) {
@@ -400,7 +399,7 @@
pin.workspaceUuid = tab.getAttribute('zen-workspace-id'); pin.workspaceUuid = tab.getAttribute('zen-workspace-id');
pin.userContextId = userContextId ? parseInt(userContextId, 10) : 0; pin.userContextId = userContextId ? parseInt(userContextId, 10) : 0;
await ZenPinnedTabsStorage.savePin(pin); await this.savePin(pin);
this.resetPinChangedUrl(tab); this.resetPinChangedUrl(tab);
await this._refreshPinnedTabs(); await this._refreshPinnedTabs();
gZenUIManager.showToast('zen-pinned-tab-replaced'); gZenUIManager.showToast('zen-pinned-tab-replaced');
@@ -423,7 +422,7 @@
entry = JSON.parse(tab.getAttribute('zen-pinned-entry')); entry = JSON.parse(tab.getAttribute('zen-pinned-entry'));
} }
await ZenPinnedTabsStorage.savePin({ await this.savePin({
uuid, uuid,
title: entry?.title || tab.label || browser.contentTitle, title: entry?.title || tab.label || browser.contentTitle,
url: entry?.url || browser.currentURI.spec, url: entry?.url || browser.currentURI.spec,
@@ -476,6 +475,15 @@
} }
} }
async savePin(pin, notifyObservers = true) {
await ZenPinnedTabsStorage.savePin(pin, notifyObservers);
// Update the cache
const existingPin = this._pinsCache.find((p) => p.uuid === pin.uuid);
if (existingPin) {
Object.assign(existingPin, pin);
}
}
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab, behavior = lazy.zenPinnedTabCloseShortcutBehavior) { _onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab, behavior = lazy.zenPinnedTabCloseShortcutBehavior) {
if (!selectedTab?.pinned) { if (!selectedTab?.pinned) {
return; return;
@@ -606,7 +614,7 @@
const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id')); const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id'));
if (pin) { if (pin) {
pin.isEssential = true; pin.isEssential = true;
ZenPinnedTabsStorage.savePin(pin); this.savePin(pin);
} }
document.getElementById('zen-essentials-container').appendChild(tab); document.getElementById('zen-essentials-container').appendChild(tab);
gBrowser.tabContainer._invalidateCachedTabs(); gBrowser.tabContainer._invalidateCachedTabs();