Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix note title sync if note is opened in multiple tabs (#7636)

01zulfi5fece5faaa17
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<EditorStore> {
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
);