From a99feb86c3c1f853f950f35648be3ce30b88ef2e Mon Sep 17 00:00:00 2001 From: Peter Aba Date: Thu, 16 Apr 2020 23:14:22 +0200 Subject: [PATCH] Improve tabs and shift tabs --- static/roadmap-form.mjs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/static/roadmap-form.mjs b/static/roadmap-form.mjs index ad54cbe..02d9706 100644 --- a/static/roadmap-form.mjs +++ b/static/roadmap-form.mjs @@ -133,7 +133,6 @@ export const roadmapForm = () => { const text = txtField.value, s0 = txtField.selectionStart, e0 = txtField.selectionEnd, - isMultiline = text.substring(s0, e0).indexOf("\n") > -1, s1 = lineStart(text, s0) - 1, e1 = lineEnd(text, e0), v0 = text.substring(s1, e1), @@ -141,13 +140,8 @@ export const roadmapForm = () => { txtField.value = text.substring(0, s1) + v1 + text.substring(e1); - if (isMultiline) { - txtField.selectionStart = s1 + 1; - txtField.selectionEnd = txtField.selectionStart + v1.length - 1; - } else { - txtField.selectionStart = s0 + 1; - txtField.selectionEnd = s0 + 1; - } + txtField.selectionStart = s0 + v1.length - v0.length; + txtField.selectionEnd = e0 + v1.length - v0.length; e.preventDefault(); }; @@ -166,7 +160,7 @@ export const roadmapForm = () => { m = lineToCur.match(/^\s+$/); // Do nothing if we're not somewhere inside the task definition - if (m === null) { + if (m === null && lineToCur !== "") { return; }