improved: insert text in todo between header and first line

This commit is contained in:
quenousimporte 2023-10-23 12:14:01 +02:00
parent 03ca5fa848
commit b33b85f8ee
1 changed files with 22 additions and 1 deletions

23
main.js
View File

@ -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() function inserttodo()
{ {
var text = prompt("Text:"); var text = prompt("Text:");
if (text) if (text)
{ {
var todo = getnote("todo"); var todo = getnote("todo");
todo.content += "\n" + text; var split = headerandtext(todo);
todo.content = split.header + "* " + text + "\n" + split.text;
if (todo == currentnote) if (todo == currentnote)
{ {
seteditorcontent(todo.content, true); seteditorcontent(todo.content, true);