Skip to content

Commit a2203dd

Browse files
committed
fix task list on numbered list
1 parent 9ef41a6 commit a2203dd

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

web_src/js/features/comp/EditorMarkdown.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ test('EditorMarkdown', () => {
2020
testInput('1. ', '');
2121

2222
testInput('- x', '- x\n- ');
23+
testInput('1. foo', '1. foo\n2. ');
2324
testInput('- [ ]', '- [ ]\n- ');
2425
testInput('- [ ] foo', '- [ ] foo\n- [ ] ');
2526
testInput('* [x] foo', '* [x] foo\n* [ ] ');
26-
testInput('1. [x] foo', '1. [x] foo\n1. [ ] ');
27+
testInput('1. [x] foo', '1. [x] foo\n2. [ ] ');
2728
});

web_src/js/features/comp/EditorMarkdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function handleNewline(textarea: HTMLTextAreaElement, e: Event) {
9797
// start a new line with the same indention and prefix
9898
let newPrefix = prefix;
9999
// a simple approach, otherwise it needs to parse the lines after the current line
100-
if (/^\d+\./.test(prefix)) newPrefix = `${Number(newPrefix.slice(0, newPrefix.indexOf('.'))) + 1}. `;
100+
const numberedListMatch = /^(\d+)\.( \[[ x]\])? /.exec(prefix);
101+
if (numberedListMatch) newPrefix = `${Number(numberedListMatch[1]) + 1}.${numberedListMatch[2] ?? ''} `;
101102
newPrefix = newPrefix.replace('[x]', '[ ]');
102103
const newLine = `\n${indention}${newPrefix}`;
103104
textarea.value = value.slice(0, selStart) + newLine + value.slice(selEnd);

0 commit comments

Comments
 (0)