Skip to content
TypeScript

fix(web): Enter on a bare "2." in the composer adds a line instead of deleting it (#18786)

Batuhan1999bac96aa3b244
diff --git a/apps/web/src/composer-list-continuation.test.ts b/apps/web/src/composer-list-continuation.test.ts
index aeab28a9b36..d5d831fb4c2 100644
--- a/apps/web/src/composer-list-continuation.test.ts
+++ b/apps/web/src/composer-list-continuation.test.ts
@@ -43,6 +43,15 @@ describe("composer list continuation", () => {
it("exits the list on an empty item", () => {
expect(applyEdit("1. foo\n2. ", listContinuationForEnter("1. foo\n2. ", 10)!)).toBe("1. foo\n");
expect(applyEdit("- ", listContinuationForEnter("- ", 2)!)).toBe("");
+ expect(applyEdit("1)\t", listContinuationForEnter("1)\t", 3)!)).toBe("");
+ expect(applyEdit("- [ ] ", listContinuationForEnter("- [ ] ", 6)!)).toBe("");
+ });
+
+ it("keeps a marker typed without a trailing space", () => {
+ expect(listContinuationForEnter("asd\n2.", 6)).toBeNull();
+ expect(listContinuationForEnter("1)", 2)).toBeNull();
+ expect(listContinuationForEnter("-", 1)).toBeNull();
+ expect(listContinuationForEnter("- [ ]", 5)).toBeNull();
});
it("ignores non-list lines and carets inside the marker", () => {
diff --git a/apps/web/src/composer-list-continuation.ts b/apps/web/src/composer-list-continuation.ts
index 4cbf52aab7f..1c2de5a4824 100644
--- a/apps/web/src/composer-list-continuation.ts
+++ b/apps/web/src/composer-list-continuation.ts
@@ -153,7 +153,7 @@ export function listContinuationForEnter(value: string, cursor: number): Compose
if (!Number.isInteger(cursor) || cursor < 0 || cursor > value.length) return null;
const line = currentLine(value, cursor);
const parsed = parseListMarker(line.text);
- if (!parsed) return null;
+ if (!parsed || parsed.marker.space === "") return null;
const markerEnd = line.start + parsed.markerEnd;
if (cursor < markerEnd) return null;
const tokens = inlineTokenRanges(value);