Skip to content

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

feat: allow trailing space in notes

thecodrrefba18b59cd6
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index 9640e6b1e..0437dffe4 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -59,6 +59,22 @@ test("note without a title should get title from content", () =>
expect(note.title).toBe("Hello This is colorful");
}));
+test("note title should allow trailing space", () =>
+ noteTest({ title: "Hello ", content: TEST_NOTE.content }).then(
+ async ({ db, id }) => {
+ let note = db.notes.note(id);
+ expect(note.title).toBe("Hello ");
+ }
+ ));
+
+test("note title should not allow newlines", () =>
+ noteTest({ title: "Hello\nhello", content: TEST_NOTE.content }).then(
+ async ({ db, id }) => {
+ let note = db.notes.note(id);
+ expect(note.title).toBe("Hello hello");
+ }
+ ));
+
test("update note", () =>
noteTest().then(async ({ db, id }) => {
let noteData = {
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index b03474171..fcc543b3a 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -232,6 +232,7 @@ function getNoteHeadline(note, content) {
}
function getNoteTitle(note, content) {
- if (note.title && note.title.trim().length > 0) return note.title.trim();
+ if (note.title && note.title.trim().length > 0)
+ return note.title.replace(/\r?\n/g, " ");
return content.toTitle();
}
diff --git a/packages/core/content-types/delta.js b/packages/core/content-types/delta.js
index 875b14724..0f86d6406 100644
--- a/packages/core/content-types/delta.js
+++ b/packages/core/content-types/delta.js
@@ -61,8 +61,8 @@ function getSubstringFromDelta(data, limit) {
for (var i = 0; i < data.length; ++i) {
const item = data[i];
if (item.insert && typeof item.insert === "string")
- substr += item.insert.trim() + " ";
- if (substr.length >= limit) return substr.substring(0, limit).trim();
+ substr += item.insert.replace(/\r?\n/g, " ");
+ if (substr.length > limit) return substr.substring(0, limit);
}
- return substr.trim();
+ return substr;
}