added: bold on ctrlb

This commit is contained in:
quenousimporte 2023-12-04 10:40:28 +01:00
parent d1b37b16ec
commit 2572378eaf
1 changed files with 31 additions and 0 deletions

31
main.js
View File

@ -403,6 +403,14 @@ function getrangecontent(range)
return md.value.substring(range.start, range.end); return md.value.substring(range.start, range.end);
} }
function currentrange()
{
return {
start: md.selectionStart,
end: md.selectionEnd
};
}
function createsubnote() function createsubnote()
{ {
var title = prompt("Subnote tite:"); var title = prompt("Subnote tite:");
@ -2624,6 +2632,25 @@ function esc(event)
} }
} }
function boldify()
{
var pos = currentrange();
var newcontent;
var offset = 2;
if (md.value.substr(pos.start - 2, 2) == "**" && md.value.substr(pos.end, 2) == "**")
{
newcontent = md.value.substr(0, pos.start - 2) + md.value.substr(pos.start, pos.end - pos.start) + md.value.substr(pos.end + 2);
offset = -2;
}
else
{
newcontent = md.value.substr(0, pos.start) + "**" + md.value.substr(pos.start, pos.end - pos.start) + "**" + md.value.substr(pos.end);
}
seteditorcontent(newcontent);
md.setSelectionRange(pos.start + offset, pos.end + offset);
}
function mainkeydownhandler() function mainkeydownhandler()
{ {
if (event.key == "Escape") if (event.key == "Escape")
@ -2643,6 +2670,10 @@ function mainkeydownhandler()
commandpalette(); commandpalette();
event.preventDefault(); event.preventDefault();
} }
else if (event.ctrlKey && event.key == "b" && md.selectionStart < md.selectionEnd)
{
boldify();
}
else if (event.ctrlKey && event.shiftKey && (event.keyCode == "40" || event.keyCode == "38")) else if (event.ctrlKey && event.shiftKey && (event.keyCode == "40" || event.keyCode == "38"))
{ {
var pos = { var pos = {