Skip to content

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

core: note title reset on updating a note

Abdullah Atta69468487c23b
diff --git a/packages/core/__tests__/notes.test.ts b/packages/core/__tests__/notes.test.ts
index c72eb94c2..156431a74 100644
--- a/packages/core/__tests__/notes.test.ts
+++ b/packages/core/__tests__/notes.test.ts
@@ -121,6 +121,19 @@ test("setting note title to empty should set the default title", () =>
expect(note?.title.startsWith("Note ")).toBe(true);
}));
+test("changing content shouldn't reset the note title ", () =>
+ noteTest({ title: "I am a note" }).then(async ({ db, id }) => {
+ await db.notes.add({
+ id,
+ content: {
+ type: TEST_NOTE.content.type,
+ data: "<p>This is a very colorful existence.</p>"
+ }
+ });
+ const note = await db.notes.note(id);
+ expect(note?.title).toBe("I am a note");
+ }));
+
test("note should get headline from content", () =>
noteTest({
...TEST_NOTE,
diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.ts
index 6cdd678c5..59690683b 100644
--- a/packages/core/src/collections/notes.ts
+++ b/packages/core/src/collections/notes.ts
@@ -109,17 +109,21 @@ export class Notes implements ICollection {
});
}
- if (item.title) {
+ if (typeof item.title !== "undefined") {
item.title = item.title.replace(NEWLINE_STRIP_REGEX, " ");
dateEdited = Date.now();
- } else {
- item.title = formatTitle(
- this.db.settings.getTitleFormat(),
- this.db.settings.getDateFormat(),
- this.db.settings.getTimeFormat(),
- headline?.split(" ").splice(0, 10).join(" ") || "",
- this.totalNotes
- );
+ }
+
+ if (!isUpdating || item.title === "") {
+ item.title =
+ item.title ||
+ formatTitle(
+ this.db.settings.getTitleFormat(),
+ this.db.settings.getDateFormat(),
+ this.db.settings.getTimeFormat(),
+ headline?.split(" ").splice(0, 10).join(" ") || "",
+ this.totalNotes
+ );
}
if (isUpdating) {