From 5fece5faaa175f14f9bb61687a59f421eb4998be Mon Sep 17 00:00:00 2001 From: 01zulfi <85733202+01zulfi@users.noreply.github.com> Date: Fri, 21 Feb 2025 12:36:07 +0500 Subject: [PATCH] web: fix note title sync if note is opened in multiple tabs (#7636) Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> --- apps/web/__e2e__/tabs.test.ts | 21 ++++++++++++++++++++- apps/web/src/stores/editor-store.ts | 13 +++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/apps/web/__e2e__/tabs.test.ts b/apps/web/__e2e__/tabs.test.ts index d6bfa252f..a0526be35 100644 --- a/apps/web/__e2e__/tabs.test.ts +++ b/apps/web/__e2e__/tabs.test.ts @@ -128,7 +128,7 @@ test("new tab button should open a new tab", async ({ page }) => { expect(await tabs[1].title()).toBe("Untitled"); }); -test("changes in a note opened in multiple tabs should sync", async ({ +test("content changes in a note opened in multiple tabs should sync", async ({ page }) => { const app = new AppModel(page); @@ -359,5 +359,24 @@ test("notes open in multiple tabs should sync color in note properties when colo expect(await note?.properties.isColored("red")).toBe(true); }); +test("notes open in multiple tabs should sync title when title is changed", async ({ + page +}) => { + const app = new AppModel(page); + await app.goto(); + const notes = await app.goToNotes(); + const note = await notes.createNote(NOTE); + await notes.editor.setTitle("Todo"); + await note?.contextMenu.openInNewTab(); + + expect(await notes.editor.getTitle()).toBe("Todo"); + + await notes.editor.setTitle("Todo - Today"); + const tabs = await notes.editor.getTabs(); + await tabs[0].click(); + + expect(await notes.editor.getTitle()).toBe("Todo - Today"); +}); + test.skip("TODO: open a locked note, switch to another note and navigate back", () => {}); test.skip("TODO: open a locked note, switch to another note, unlock the note and navigate back", () => {}); diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts index ce14cd019..61614add0 100644 --- a/apps/web/src/stores/editor-store.ts +++ b/apps/web/src/stores/editor-store.ts @@ -1012,6 +1012,19 @@ class EditorStore extends BaseStore { sessionId }); } + + if (partial.note?.title !== undefined) { + const { sessions } = this.get(); + for (const session of sessions) { + if ("note" in session && session.note.id === note.id) { + this.updateSession(session.id, undefined, { + note, + title: note.title + }); + } + } + } + setDocumentTitle( settingStore.get().hideNoteTitle ? undefined : note.title );