fix: create todo if not exists

removed: bullet in new todo entry
refactor: remove unused title param in default header
fix: create new note if not in list
This commit is contained in:
quenousimporte 2023-11-16 10:47:14 +01:00
parent bcff1fbf08
commit 47b12a0d04
1 changed files with 7 additions and 7 deletions

14
main.js
View File

@ -1169,9 +1169,9 @@ function inserttodo()
var text = prompt("Text:"); var text = prompt("Text:");
if (text) if (text)
{ {
var todo = getnote("todo"); var todo = getorcreate("todo", "");
var split = headerandtext(todo); var split = headerandtext(todo);
todo.content = split.header + "* " + text + "\n" + split.text; todo.content = split.header + text + "\n" + split.text;
if (todo == currentnote) if (todo == currentnote)
{ {
seteditorcontent(todo.content, true); seteditorcontent(todo.content, true);
@ -1255,7 +1255,7 @@ function loadstorage()
currentnote = getnote(title); currentnote = getnote(title);
if (!currentnote) if (!currentnote)
{ {
var newcontent = defaultheaders(title, tags); var newcontent = defaultheaders(tags);
currentnote = {title: title, content: newcontent, pos: newcontent.length}; currentnote = {title: title, content: newcontent, pos: newcontent.length};
localdata.unshift(currentnote); localdata.unshift(currentnote);
} }
@ -2394,7 +2394,7 @@ function searchandloadnote()
{ {
selectnote().then(selected => selectnote().then(selected =>
{ {
loadnote(selected.text); loadnote(selected.text || selected);
}); });
} }
@ -2549,7 +2549,7 @@ function insertheader()
{ {
if (preview.hidden && !md.value.startsWith("---\n")) if (preview.hidden && !md.value.startsWith("---\n"))
{ {
var headers = defaultheaders(currentnote.title); var headers = defaultheaders();
seteditorcontent(headers + md.value); seteditorcontent(headers + md.value);
setpos(27); setpos(27);
} }
@ -2937,7 +2937,7 @@ function bindfile(note)
setpos(note.pos || 0); setpos(note.pos || 0);
} }
function defaultheaders(title, tags = "") function defaultheaders(tags = "")
{ {
return [ return [
"---", "---",
@ -2949,7 +2949,7 @@ function defaultheaders(title, tags = "")
function loadnote(name) function loadnote(name)
{ {
var note = getorcreate(name, defaultheaders(name), true); var note = getorcreate(name, defaultheaders(), true);
bindfile(note); bindfile(note);
stat.cur.q = 0; stat.cur.q = 0;