Fix: Update pinned tab title in storage on rename

This commit addresses an issue where renaming a pinned tab wouldn't update the title stored in `ZenPinnedTabsStorage`.

The following changes were made:

- Modified `ZenUIManager.mjs` to asynchronously call `ZenPinnedTabsStorage.updatePinTitle` when a tab is renamed via the keyboard. This ensures the stored title is synchronized with the displayed title.
- Added the `updatePinTitle` function to `ZenPinnedTabsStorage.mjs`. This function updates the title of a zen pin within the database.

This ensures consistency between the tab title displayed in the UI and the title stored for pinned tabs.
This commit is contained in:
Kristijan Ribarić
2025-02-17 15:56:57 +01:00
parent 08baf5ae87
commit a6e446e5cf
2 changed files with 58 additions and 1 deletions

View File

@@ -665,7 +665,7 @@ var gZenVerticalTabsManager = {
target.appendChild(child);
},
renameTabKeydown(event) {
async renameTabKeydown(event) {
if (event.key === 'Enter') {
let label = this._tabEdited.querySelector('.tab-label-container-editing');
let input = this._tabEdited.querySelector('#tab-label-input');
@@ -681,6 +681,11 @@ var gZenVerticalTabsManager = {
} else {
gBrowser.setTabTitle(this._tabEdited);
}
const pinId = this._tabEdited.getAttribute('zen-pin-id');
if (pinId) {
// Update pin title in storage
await ZenPinnedTabsStorage.updatePinTitle(pinId, this._tabEdited.label);
}
// Maybe add some confetti here?!?
gZenUIManager.motion.animate(

View File

@@ -351,6 +351,58 @@ var ZenPinnedTabsStorage = {
this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs));
},
async updatePinTitle(uuid, newTitle, notifyObservers = true) {
if (!uuid || typeof newTitle !== 'string') {
throw new Error('Invalid parameters: uuid and newTitle are required');
}
const changedUUIDs = new Set();
await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.updatePinTitle', async (db) => {
await db.executeTransaction(async () => {
const now = Date.now();
// Update the pin's title
const result = await db.execute(
`
UPDATE zen_pins
SET title = :newTitle,
updated_at = :now
WHERE uuid = :uuid
`,
{
uuid,
newTitle,
now,
}
);
// Only proceed with change tracking if a row was actually updated
if (result.rowsAffected > 0) {
changedUUIDs.add(uuid);
// Record the change
await db.execute(
`
INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp)
VALUES (:uuid, :timestamp)
`,
{
uuid,
timestamp: Math.floor(now / 1000),
}
);
await this.updateLastChangeTimestamp(db);
}
});
});
if (notifyObservers && changedUUIDs.size > 0) {
this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs));
}
},
async __dropTables() {
await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.__dropTables', async (db) => {
await db.execute(`DROP TABLE IF EXISTS zen_pins`);