added: autosort todo upon opening

This commit is contained in:
quenousimporte 2023-12-12 09:57:29 +01:00
parent 263af2a863
commit 45b6b9be4b
1 changed files with 52 additions and 35 deletions

33
main.js
View File

@ -13,7 +13,8 @@ var defaultsettings =
password: "",
sync: false,
tagsinlists: true,
uselinkpopup: true
uselinkpopup: true,
autosorttodo: true
};
//builtin
@ -264,7 +265,7 @@ var commands = [
},
{
hint: "Sort todo.txt list",
action: sorttodotxt
action: sortcurrentastodo
},
{
hint: "Sort text",
@ -2400,16 +2401,19 @@ function searchandloadnote()
});
}
function currentistodo()
function istodo(note)
{
return currentnote.title.includes("todo") || gettags(currentnote).includes("todo");
return note.title.includes("todo") || gettags(note).includes("todo");
}
function sorttodotxt()
function currentistodo()
{
if (currentistodo())
return istodo(currentnote);
}
function sorttodotxt(note)
{
var hat = headerandtext(currentnote);
var hat = headerandtext(note);
var olditems = hat.text.split("\n");
var prio = [];
var std = [];
@ -2438,7 +2442,15 @@ function sorttodotxt()
prio = prio.sort((a,b) => a.localeCompare(b));
done = done.sort((a,b) => a.localeCompare(b));
var all = prio.concat(std).concat(done);
seteditorcontent(hat.header + all.join("\n"));
note.content = hat.header + all.join("\n");
}
function sortcurrentastodo()
{
if (currentistodo())
{
sorttodotxt(currentnote);
seteditorcontent(currentnote.content);
}
}
@ -3003,6 +3015,11 @@ function loadnote(name)
}
}
if (settings.autosorttodo && istodo(note))
{
sorttodotxt(note);
}
bindfile(note);
stat.cur.q = 0;