mirror of
https://github.com/zen-browser/desktop.git
synced 2025-10-05 09:26:34 +00:00
Fix: Properly update pinned tab titles after edit
This commit addresses an issue where edited pinned tab titles were not consistently updated across all windows and in storage. The following changes were made: - **ZenUIManager.mjs:** Removed redundant `pinId` variable and directly checked `zen-pin-id` attribute. - **ZenPinnedTabsStorage.mjs:** Added `edited_title` column to the `zen_pins` table to track if a pin's title has been manually edited. Also, the `updatePinTitle` function now accepts an `isEdited` flag (defaults to true) and updates the `edited_title` column accordingly. - **ZenPinnedTabManager.mjs:** The `updatePinTitle` function was added to handle the update of pin titles. It updates the title in storage using `ZenPinnedTabsStorage.updatePinTitle`, refreshes the pinned tabs, and then iterates through all browser windows to update the labels of corresponding pinned tabs. Also, a check was added to `_initializePinnedTabs` to set the `zen-has-static-label` attribute on tabs with `editedTitle` set to `true`. - **ZenWorkspaces.mjs:** Added a null check for `activeWorkspaceStrip` to avoid errors when it's not available. These changes ensure that when a pinned tab title is edited, the updated title is correctly persisted in storage and reflected across all open windows. The `edited_title` flag allows distinguishing between default titles and custom ones.
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
}
|
||||
|
||||
if (onInit) {
|
||||
await this._refreshPinnedTabs(newWorkspace, { init: onInit });
|
||||
await this._refreshPinnedTabs({ init: onInit });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
async _refreshPinnedTabs(currentWorkspace, { init = false } = {}) {
|
||||
async _refreshPinnedTabs({ init = false } = {}) {
|
||||
await this._initializePinsCache();
|
||||
await this._initializePinnedTabs(init, currentWorkspace);
|
||||
await this._initializePinnedTabs(init);
|
||||
}
|
||||
|
||||
async _initializePinsCache() {
|
||||
@@ -141,7 +141,7 @@
|
||||
return this._pinsCache;
|
||||
}
|
||||
|
||||
async _initializePinnedTabs(init = false, currentWorkspace) {
|
||||
async _initializePinnedTabs(init = false) {
|
||||
const pins = this._pinsCache;
|
||||
if (!pins?.length) {
|
||||
return;
|
||||
@@ -213,6 +213,10 @@
|
||||
newTab.setAttribute('zen-essential', 'true');
|
||||
}
|
||||
|
||||
if (pin.editedTitle) {
|
||||
newTab.setAttribute('zen-has-static-label', 'true');
|
||||
}
|
||||
|
||||
// Initialize browser state if needed
|
||||
if (!newTab.linkedBrowser._remoteAutoRemoved) {
|
||||
let state = {
|
||||
@@ -349,7 +353,7 @@
|
||||
|
||||
await ZenPinnedTabsStorage.savePin(pin);
|
||||
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
|
||||
await this._refreshPinnedTabs(currentWorkspace);
|
||||
await this._refreshPinnedTabs();
|
||||
}
|
||||
|
||||
async _setPinnedAttributes(tab) {
|
||||
@@ -386,7 +390,7 @@
|
||||
return;
|
||||
}
|
||||
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
|
||||
await this._refreshPinnedTabs(currentWorkspace);
|
||||
await this._refreshPinnedTabs();
|
||||
}
|
||||
|
||||
async _removePinnedAttributes(tab, isClosing = false) {
|
||||
@@ -411,7 +415,7 @@
|
||||
}
|
||||
}
|
||||
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
|
||||
await this._refreshPinnedTabs(currentWorkspace);
|
||||
await this._refreshPinnedTabs();
|
||||
}
|
||||
|
||||
_initClosePinnedTabShortcut() {
|
||||
@@ -707,6 +711,33 @@
|
||||
return document.documentElement.getAttribute('zen-sidebar-expanded') === 'true';
|
||||
}
|
||||
|
||||
async updatePinTitle(tab, newTitle, isEdited = true, notifyObservers = true) {
|
||||
const uuid = tab.getAttribute('zen-pin-id');
|
||||
await ZenPinnedTabsStorage.updatePinTitle(uuid, newTitle, isEdited, notifyObservers);
|
||||
|
||||
await this._refreshPinnedTabs();
|
||||
|
||||
const browsers = Services.wm.getEnumerator('navigator:browser');
|
||||
|
||||
// update the label for the same pin across all windows
|
||||
for (const browser of browsers) {
|
||||
const tabs = browser.gBrowser.tabs;
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
const tabToEdit = tabs[i];
|
||||
if (tabToEdit.getAttribute('zen-pin-id') === uuid && tabToEdit !== tab) {
|
||||
tabToEdit.removeAttribute('zen-has-static-label');
|
||||
if (isEdited) {
|
||||
gBrowser._setTabLabel(tabToEdit, newTitle);
|
||||
tabToEdit.setAttribute('zen-has-static-label', 'true');
|
||||
} else {
|
||||
gBrowser.setTabTitle(tabToEdit);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
applyDragoverClass(event, draggedTab) {
|
||||
const pinnedTabsTarget = event.target.closest('#vertical-pinned-tabs-container');
|
||||
const essentialTabsTarget = event.target.closest('#zen-essentials-container');
|
||||
|
Reference in New Issue
Block a user