core: note title reset on updating a note

This commit is contained in:
Abdullah Atta
2024-09-23 17:26:50 +05:00
parent 0809b5b701
commit 69468487c2
2 changed files with 26 additions and 9 deletions

View File

@@ -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,

View File

@@ -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) {