From b33b85f8ee4bd9cf2a7520d0b0954bbe8c9f2ff6 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Mon, 23 Oct 2023 12:14:01 +0200 Subject: [PATCH] improved: insert text in todo between header and first line --- main.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index f2a3197..d6eb382 100644 --- a/main.js +++ b/main.js @@ -1087,13 +1087,34 @@ function downloadnotes() }); } +function headerandtext(note) +{ + var content = note.content; + var result = + { + header: "", + text: content + }; + if (content.startsWith("---\n")) + { + var end = content.indexOf("---\n", 4); + if (end > -1) + { + result.header = content.substring(0, end + 4); + result.text = content.substring(end + 4); + } + } + return result; +} + function inserttodo() { var text = prompt("Text:"); if (text) { var todo = getnote("todo"); - todo.content += "\n" + text; + var split = headerandtext(todo); + todo.content = split.header + "* " + text + "\n" + split.text; if (todo == currentnote) { seteditorcontent(todo.content, true);