added: autochecklist

This commit is contained in:
quenousimporte 2024-01-16 15:15:23 +01:00
parent d859aec44d
commit 5bb7742d15
1 changed files with 31 additions and 7 deletions

38
main.js
View File

@ -19,7 +19,7 @@ var defaultsettings =
};
//builtin
var markerslist = ["* ", "- ", " * ", " - ", ">> ", "> ", "=> ", "— ", "[ ] ", " ", "• ", "- [ ]"];
var markerslist = ["* ", "- ", " * ", " - ", ">> ", "> ", "=> ", "— ", "[ ] ", " ", "• ", "- [ ]", "[x] ", "- [x]"];
var codelanguages = ["xml", "js", "sql"];
var tagmark = "+";
@ -816,17 +816,33 @@ function showlinkdialog(link)
notepage.appendChild(div);
}
function checkatpos(pos)
{
if (pos > 0 && md.value[pos - 1] == "[" && md.value[pos + 1] == "]")
{
return {
pos: pos,
val: md.value[pos]
};
}
return null;
}
function clickedcheck()
{
return checkatpos(md.selectionStart) || checkatpos(md.selectionStart + 1) || checkatpos(md.selectionStart - 1);
}
function clickeditor()
{
if (!saved)
{
console.log("Not saved, ctrl+click ignored.");
return;
}
var word, link;
if (event.ctrlKey)
{
if (!saved)
{
console.log("Not saved, ctrl+click ignored.");
return;
}
link = linkatpos();
var tag = tagatpos();
word = wordatpos();
@ -845,6 +861,14 @@ function clickeditor()
window.open(word, '_blank');
}
}
else if (clickedcheck())
{
var res = clickedcheck();
seteditorcontent(md.value.substring(0, res.pos)
+ (res.val == " " ? "x" : " ")
+ md.value.substring(res.pos + 1));
setpos(res.pos);
}
else if (settings.uselinkpopup)
{
removelinkdialog();