Skip to content
TypeScript

fix(web): Backspace no longer re-nests a checkbox under a bullet (#27384)

Lee Keun Hwee868524f259e5
diff --git a/apps/web/src/composer-list-split.browser.test.ts b/apps/web/src/composer-list-split.browser.test.ts
index a1d09bccab5..632bb1ff4d3 100644
--- a/apps/web/src/composer-list-split.browser.test.ts
+++ b/apps/web/src/composer-list-split.browser.test.ts
@@ -68,6 +68,25 @@ describe("Backspace at the start of a line", () => {
editor.commands.keyboardShortcut("Backspace");
expect(storedDraft(editor)).toBe(expected);
});
+
+ // Neither item has a list of its own kind one level up to lift into.
+ it.each([
+ ["- a\n - [ ] x\n - [ ] y", "- a\n - [ ] xy"],
+ ["- [ ] a\n - x\n - y", "- [ ] a\n - xy"],
+ ["- a\n - [ ] y\n - [ ] q", "- ay\n - [ ] q"],
+ ])("joins y in %j onto the line above", (value, expected) => {
+ using editor = makeEditor(value);
+ placeCaret(editor, "y");
+ editor.commands.keyboardShortcut("Backspace");
+ expect(storedDraft(editor)).toBe(expected);
+ });
+
+ it("removes an empty checkbox under a bullet", () => {
+ using editor = makeEditor("- a\n - [ ] x\n - [ ]");
+ editor.view.dispatch(editor.state.tr.setSelection(TextSelection.atEnd(editor.state.doc)));
+ editor.commands.keyboardShortcut("Backspace");
+ expect(storedDraft(editor)).toBe("- a\n - [ ] x");
+ });
});
describe("blocks that a list item or quote cannot hold", () => {
diff --git a/apps/web/src/composer-rich-text-doc.ts b/apps/web/src/composer-rich-text-doc.ts
index a6dded080f0..7025b687850 100644
--- a/apps/web/src/composer-rich-text-doc.ts
+++ b/apps/web/src/composer-rich-text-doc.ts
@@ -1,4 +1,4 @@
-import { joinBackward, joinTextblockBackward, joinTextblockForward } from "@tiptap/pm/commands";
+import { joinTextblockBackward, joinTextblockForward } from "@tiptap/pm/commands";
import {
Fragment,
Mark,
@@ -1203,7 +1203,8 @@ function backspaceAcrossList(editor: Editor): boolean {
return moved;
};
// can() skips the schema check and can accept tasks with no parent list to lift into.
- return editor.chain().command(lift).run() || joinBackward(state, editor.view.dispatch);
+ // Those join the line above; joinBackward would re-nest them or select the parent line.
+ return editor.chain().command(lift).run() || joinTextblockBackward(state, editor.view.dispatch);
}
const before = $from.depth === 1 ? $from.node(0).maybeChild($from.index(0) - 1) : null;
if (before && LIST_NODE_NAMES.has(before.type.name) && $from.parent.type.name !== "codeBlock") {