added: command to sort todo.txt

This commit is contained in:
quenousimporte 2023-10-25 11:28:12 +02:00
parent 3f007a3d45
commit 464d4c1bf6
1 changed files with 42 additions and 1 deletions

43
main.js
View File

@ -270,6 +270,10 @@ var commands = [
hint: "Replace",
shortcut: "ctrl+h",
action: searchandreplace
},
{
hint: "Sort todo.txt list",
action: sorttodotxt
}];
var snippets = [
@ -2082,7 +2086,7 @@ function rawline2html(line, index, options)
}
// todo.txt
if (currentnote.title.includes("todo") || gettags(currentnote).includes("todo"))
if (currentistodo())
{
if (line.startsWith("x "))
{
@ -2262,6 +2266,43 @@ function searchandloadnote()
selectnote().then(loadnote);
}
function currentistodo()
{
return currentnote.title.includes("todo") || gettags(currentnote).includes("todo");
}
function sorttodotxt()
{
if (currentistodo())
{
var hat = headerandtext(currentnote);
var olditems = hat.text.split("\n");
var prio = [];
var std = [];
var done = [];
olditems.forEach(item =>
{
if (item)
{
if (item.startsWith("("))
{
prio.push(item);
}
else if (item.startsWith("x "))
{
done.push(item);
}
else
{
std.push(item);
}
}
});
var all = prio.sort((a,b) => a.localeCompare(b)).concat(std).concat(done.sort((a,b) => a.localeCompare(b)));
seteditorcontent(hat.header + all.join("\n"));
}
}
function searchandreplace()
{
var oldvalue = prompt("Search:");