Skip to content

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

fix: empty note is not automatically deleted

thecodrr1785ce95711a
diff --git a/packages/core/__tests__/lookup.test.js b/packages/core/__tests__/lookup.test.js
index 8739c25f4..059113367 100644
--- a/packages/core/__tests__/lookup.test.js
+++ b/packages/core/__tests__/lookup.test.js
@@ -7,7 +7,7 @@ import {
TEST_NOTE,
TEST_NOTEBOOK,
notebookTest,
- TEST_NOTEBOOK2
+ TEST_NOTEBOOK2,
} from "./utils";
beforeEach(async () => {
@@ -17,7 +17,7 @@ beforeEach(async () => {
//TODO
test("search notes", () =>
noteTest({
- content: { delta: "5", text: "5" }
+ content: { delta: [{ insert: "5" }], text: "5" },
}).then(async ({ db }) => {
await db.notes.add(TEST_NOTE);
let filtered = await db.lookup.notes(db.notes.all, "5");
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index 830c83b14..1b84ada33 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -84,10 +84,10 @@ test("updating empty note should delete it", () =>
noteTest().then(async ({ db, id }) => {
id = await db.notes.add({
id,
- title: "\n\n",
+ title: "\n",
content: {
- text: "",
- delta: [],
+ text: "\n",
+ delta: [{ insert: "\n" }],
},
});
expect(id).toBeUndefined();
@@ -109,7 +109,7 @@ test("note with text longer than 150 characters should have ... in the headline"
test("get favorite notes", () =>
noteTest({
favorite: true,
- content: { delta: "Hello", text: "Hello" },
+ content: { delta: [{ insert: "Hello" }], text: "Hello" },
}).then(({ db }) => {
expect(db.notes.favorites.length).toBeGreaterThan(0);
}));
@@ -117,7 +117,7 @@ test("get favorite notes", () =>
test("get pinned notes", () =>
noteTest({
pinned: true,
- content: { delta: "Hello", text: "Hello" },
+ content: { delta: [{ insert: "Hello" }], text: "Hello" },
}).then(({ db }) => {
expect(db.notes.pinned.length).toBeGreaterThan(0);
}));
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index 547751cb4..2358aa7fc 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -228,10 +228,23 @@ function isNoteEmpty(note) {
const isTitleEmpty = !title || !title.trim().length;
const isTextEmpty = !isHex(text) && (!text || !text.trim().length);
- const isDeltaEmpty = !isHex(delta) && (!delta || !delta.ops);
+ const isDeltaEmpty = !isHex(delta) && _isDeltaEmpty(delta);
return !locked && isTitleEmpty && isTextEmpty && isDeltaEmpty;
}
+function _isDeltaEmpty(delta) {
+ let obj = delta;
+ if (delta.constructor === Object) obj = delta.ops;
+
+ return (
+ !obj ||
+ obj
+ .map((o) => o.insert)
+ .join("")
+ .trim().length <= 0
+ );
+}
+
function getNoteHeadline(note) {
if (note.locked) return "";
const text = getText(note);