mirror of
https://github.com/zen-browser/desktop.git
synced 2025-09-05 19:08:18 +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:
@@ -681,10 +681,9 @@ var gZenVerticalTabsManager = {
|
||||
} else {
|
||||
gBrowser.setTabTitle(this._tabEdited);
|
||||
}
|
||||
const pinId = this._tabEdited.getAttribute('zen-pin-id');
|
||||
if (pinId) {
|
||||
if (this._tabEdited.getAttribute('zen-pin-id')) {
|
||||
// Update pin title in storage
|
||||
await ZenPinnedTabsStorage.updatePinTitle(pinId, this._tabEdited.label);
|
||||
await gZenPinnedTabManager.updatePinTitle(this._tabEdited, this._tabEdited.label, !!newName);
|
||||
}
|
||||
|
||||
// Maybe add some confetti here?!?
|
||||
|
@@ -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');
|
||||
|
@@ -24,6 +24,19 @@ var ZenPinnedTabsStorage = {
|
||||
)
|
||||
`);
|
||||
|
||||
const columns = await db.execute(`PRAGMA table_info(zen_pins)`);
|
||||
const columnNames = columns.map((row) => row.getResultByName('name'));
|
||||
|
||||
// Helper function to add column if it doesn't exist
|
||||
const addColumnIfNotExists = async (columnName, definition) => {
|
||||
if (!columnNames.includes(columnName)) {
|
||||
await db.execute(`ALTER TABLE zen_pins ADD COLUMN ${columnName} ${definition}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Add edited_title column if it doesn't exist
|
||||
await addColumnIfNotExists('edited_title', 'BOOLEAN NOT NULL DEFAULT 0');
|
||||
|
||||
// Create indices
|
||||
await db.execute(`
|
||||
CREATE INDEX IF NOT EXISTS idx_zen_pins_uuid ON zen_pins(uuid)
|
||||
@@ -152,6 +165,7 @@ var ZenPinnedTabsStorage = {
|
||||
isEssential: Boolean(row.getResultByName('is_essential')),
|
||||
isGroup: Boolean(row.getResultByName('is_group')),
|
||||
parentUuid: row.getResultByName('parent_uuid'),
|
||||
editedTitle: Boolean(row.getResultByName('edited_title')),
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -176,6 +190,7 @@ var ZenPinnedTabsStorage = {
|
||||
isEssential: Boolean(row.getResultByName('is_essential')),
|
||||
isGroup: Boolean(row.getResultByName('is_group')),
|
||||
parentUuid: row.getResultByName('parent_uuid'),
|
||||
editedTitle: Boolean(row.getResultByName('edited_title')),
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -351,7 +366,7 @@ var ZenPinnedTabsStorage = {
|
||||
this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs));
|
||||
},
|
||||
|
||||
async updatePinTitle(uuid, newTitle, notifyObservers = true) {
|
||||
async updatePinTitle(uuid, newTitle, isEdited = true, notifyObservers = true) {
|
||||
if (!uuid || typeof newTitle !== 'string') {
|
||||
throw new Error('Invalid parameters: uuid and newTitle are required');
|
||||
}
|
||||
@@ -362,17 +377,19 @@ var ZenPinnedTabsStorage = {
|
||||
await db.executeTransaction(async () => {
|
||||
const now = Date.now();
|
||||
|
||||
// Update the pin's title
|
||||
// Update the pin's title and edited_title flag
|
||||
const result = await db.execute(
|
||||
`
|
||||
UPDATE zen_pins
|
||||
SET title = :newTitle,
|
||||
edited_title = :isEdited,
|
||||
updated_at = :now
|
||||
WHERE uuid = :uuid
|
||||
`,
|
||||
{
|
||||
uuid,
|
||||
newTitle,
|
||||
isEdited,
|
||||
now,
|
||||
}
|
||||
);
|
||||
|
@@ -154,7 +154,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
}
|
||||
|
||||
get tabboxChildren() {
|
||||
return this.activeWorkspaceStrip.children;
|
||||
return this.activeWorkspaceStrip?.children || [];
|
||||
}
|
||||
|
||||
get pinnedTabsContainer() {
|
||||
|
Reference in New Issue
Block a user