Skip to content

Commit

Permalink
Improve tabs and shift tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
peteraba committed Apr 16, 2020
1 parent 0718390 commit a99feb8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions static/roadmap-form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,15 @@ 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),
v1 = applyShift(v0, e.shiftKey);

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();
};
Expand All @@ -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;
}

Expand Down

0 comments on commit a99feb8

Please sign in to comment.