From 43b70a187b28c3cf88d04a9a59a60b6eb843fa2a Mon Sep 17 00:00:00 2001 From: quenousimporte <76260127+quenousimporte@users.noreply.github.com> Date: Thu, 2 Feb 2023 21:42:07 +0100 Subject: [PATCH] added: tab and untab --- main.js | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 8bf945f..2778dd2 100644 --- a/main.js +++ b/main.js @@ -389,7 +389,7 @@ function createsubnote(suggestedtitle) } var range = getlinesrange(); var content = md.value.substring(range.start, range.end); - filter.placeholder = "Subnote title..."; + filter.placeholder = "Create subnote..."; searchinlist(name) .then(title => { @@ -2021,11 +2021,43 @@ function editorkeydown() setpos(getpos() - 2); insert(" ", 2); } - // disable tab - /*else + else { - insert(" "); - }*/ + var init = { + start: md.selectionStart, + end: md.selectionEnd + }; + var range = getlinesrange(); + range.start--; + range.end--; + var selection = md.value.substring(range.start, range.end); + var newtext; + if (event.shiftKey) + { + newtext = selection.replaceAll("\n ", "\n"); + } + else + { + newtext = selection.replaceAll("\n", "\n "); + + } + md.value = md.value.substring(0, range.start) + + newtext + + md.value.substring(range.end); + + var shift = 0; + if (newtext.length < selection.length) + { + shift = -4; + } + else if (newtext.length > selection.length) + { + shift = 4; + } + + md.selectionStart = init.start + shift; + md.selectionEnd = init.end + (newtext.length - selection.length); + } } else if (event.key === "[" && before(1) == "[") {