Skip to content

Commit 9ef41a6

Browse files
committed
fix textarea newline handle
1 parent 7553ae1 commit 9ef41a6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

web_src/js/features/comp/EditorMarkdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ function handleNewline(textarea: HTMLTextAreaElement, e: Event) {
9292
if (!line) {
9393
// clear current line if we only have i.e. '1. ' and the user presses enter again to finish creating a list
9494
textarea.value = value.slice(0, lineStart) + value.slice(lineEnd);
95+
textarea.setSelectionRange(selStart - prefix.length, selStart - prefix.length);
9596
} else {
9697
// start a new line with the same indention and prefix
9798
let newPrefix = prefix;
9899
// a simple approach, otherwise it needs to parse the lines after the current line
99-
if (/^\d+\./.test(prefix)) newPrefix = `1. ${newPrefix.slice(newPrefix.indexOf('.') + 2)}`;
100+
if (/^\d+\./.test(prefix)) newPrefix = `${Number(newPrefix.slice(0, newPrefix.indexOf('.'))) + 1}. `;
100101
newPrefix = newPrefix.replace('[x]', '[ ]');
101102
const newLine = `\n${indention}${newPrefix}`;
102103
textarea.value = value.slice(0, selStart) + newLine + value.slice(selEnd);

0 commit comments

Comments
 (0)