Skip to content

Commit 8024d10

Browse files
committed
improve comments
1 parent 1c8c42d commit 8024d10

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

web_src/js/features/comp/EditorMarkdown.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ function handleNewline(textarea, e) {
5050
const value = textarea.value;
5151

5252
// find the current line
53+
// * if selStart is 0, lastIndexOf(..., -1) is the same as lastIndexOf(..., 0)
54+
// * if lastIndexOf reruns -1, lineStart is 0 and it is still correct.
5355
const lineStart = value.lastIndexOf('\n', selStart - 1) + 1;
5456
let lineEnd = value.indexOf('\n', selStart);
5557
lineEnd = lineEnd < 0 ? value.length : lineEnd;
@@ -61,6 +63,7 @@ function handleNewline(textarea, e) {
6163
line = line.slice(indention.length);
6264

6365
// parse the prefixes: "1. ", "- ", "* ", "[ ] ", "[x] "
66+
// there must be a space after the prefix because none of "1.foo" / "-foo" is a list item
6467
const prefixMatch = /^([0-9]+\.|[-*]|\[ \]|\[x\])\s/.exec(line);
6568
let prefix = '';
6669
if (prefixMatch) {
@@ -73,7 +76,7 @@ function handleNewline(textarea, e) {
7376

7477
e.preventDefault();
7578
if (!line) {
76-
// clear current line
79+
// clear current line if we only have i.e. '1. ' and the user presses enter again to finish creating a list
7780
textarea.value = value.slice(0, lineStart) + value.slice(lineEnd);
7881
} else {
7982
// start a new line with the same indention and prefix

0 commit comments

Comments
 (0)