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

34
main.js
View File

@ -19,7 +19,7 @@ var defaultsettings =
}; };
//builtin //builtin
var markerslist = ["* ", "- ", " * ", " - ", ">> ", "> ", "=> ", "— ", "[ ] ", " ", "• ", "- [ ]"]; var markerslist = ["* ", "- ", " * ", " - ", ">> ", "> ", "=> ", "— ", "[ ] ", " ", "• ", "- [ ]", "[x] ", "- [x]"];
var codelanguages = ["xml", "js", "sql"]; var codelanguages = ["xml", "js", "sql"];
var tagmark = "+"; var tagmark = "+";
@ -816,17 +816,33 @@ function showlinkdialog(link)
notepage.appendChild(div); 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() function clickeditor()
{ {
var word, link;
if (event.ctrlKey)
{
if (!saved) if (!saved)
{ {
console.log("Not saved, ctrl+click ignored."); console.log("Not saved, ctrl+click ignored.");
return; return;
} }
var word, link;
if (event.ctrlKey)
{
link = linkatpos(); link = linkatpos();
var tag = tagatpos(); var tag = tagatpos();
word = wordatpos(); word = wordatpos();
@ -845,6 +861,14 @@ function clickeditor()
window.open(word, '_blank'); 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) else if (settings.uselinkpopup)
{ {
removelinkdialog(); removelinkdialog();