drop todotxt support except done

This commit is contained in:
quenousimporte 2024-03-08 16:46:58 +01:00
parent 13906080b5
commit 893b23a985
1 changed files with 3 additions and 83 deletions

82
main.js
View File

@ -14,8 +14,7 @@ var defaultsettings =
password: "",
sync: false,
tagsinlists: true,
uselinkpopup: true,
autosorttodo: true
uselinkpopup: true
};
//builtin
@ -208,10 +207,6 @@ var commands = [
shortcut: "ctrl+h",
action: searchandreplace
},
{
hint: "Sort todo.txt list",
action: sortcurrentastodo
},
{
hint: "Sort text",
action: sortselection
@ -219,10 +214,6 @@ var commands = [
{
hint: "Show backlinks",
action: backlinks
},
{
hint: "Remove completed tasks",
action: purgetodo
}];
var snippets = [
@ -273,14 +264,6 @@ function genguid()
return crypto.randomUUID();
}
function purgetodo()
{
if (currentistodo() && confirm("Remove completed tasks?"))
{
seteditorcontent(md.value.replace(/\nx .*/g, ""));
}
}
function seteditorcontent(content)
{
md.value = content;
@ -2096,20 +2079,10 @@ function rawline2html(line, index, options)
}
}
// todotxt
if (currentistodo())
{
if (line.startsWith("x "))
{
line = "<span class='color-todo-complete'>" + line + "</span>";
}
else
{
line = line.replace(/(\(\w\))/g, "<span class='color-todo-priority'>$1</span>");
line = line.replace(/(@\w*)/g, "<span class='color-todo-project'>$1</span>");
line = line.replace(/(\s\+\w*)/g, "<span class='color-todo-context'>$1</span>");
}
}
// inline code
line = line.replace(/`(.*)`/, "<span class='color-code'>`$1`</span>");
@ -2296,59 +2269,11 @@ function searchandloadnote()
});
}
function currentistodo()
{
return istodo(title.value, md.value);
}
function istodo(title, content)
{
return title.includes("todo") || gettags(content).includes("todo");
}
function sorttodotxt(content)
{
var hat = headerandtext(content);
var olditems = hat.text.split("\n");
var prio = [];
var std = [];
var done = [];
olditems.forEach(item =>
{
if (item)
{
if (item.startsWith("("))
{
item = item.substring(4);
var priority = String.fromCharCode(65 + prio.length);
prio.push(`(${priority}) ${item}`);
}
else if (item.startsWith("x "))
{
done.push(item);
}
else
{
std.push(item);
}
}
});
prio = prio.sort((a,b) => a.localeCompare(b));
done = done.sort((a,b) => a.localeCompare(b));
var all = prio.concat(std).concat(done);
return hat.header + all.join("\n");
}
function sortcurrentastodo()
{
if (currentistodo())
{
var content = sorttodotxt(md.value);
seteditorcontent(content);
}
}
function searchandreplace()
{
var oldvalue = prompt("Search:");
@ -2874,11 +2799,6 @@ function loadnote(title)
}
}
if (settings.autosorttodo && istodo(title, content))
{
content = sorttodotxt(content);
}
bind(item.title, content, item.pos);
if (!preview.hidden || (preview.hidden && (gettags(md.value).indexOf("preview") !== -1)))