Skip to content

Commit 24da517

Browse files
committed
fix(web): Backspace no longer re-nests a checkbox under a bullet
A checkbox nested under a bullet (or a bullet under a checkbox) has no list of its own kind one level up, so lifting it fails. The fallback, joinBackward, then wrapped the item into a new list under the item above, and the next Backspace lifted it back out, so the line could never be deleted. For the first such item with a sibling below, it fell through to selecting the parent line, and a second Backspace deleted the parent's text. Join the line onto the one above with joinTextblockBackward instead, which is what the fallback was meant to do.
1 parent c8a606c commit 24da517

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎apps/web/src/composer-list-split.browser.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ describe("Backspace at the start of a line", () => {
6868
editor.commands.keyboardShortcut("Backspace");
6969
expect(storedDraft(editor)).toBe(expected);
7070
});
71+
72+
// Neither item has a list of its own kind one level up to lift into.
73+
it.each([
74+
["- a\n - [ ] x\n - [ ] y", "- a\n - [ ] xy"],
75+
["- [ ] a\n - x\n - y", "- [ ] a\n - xy"],
76+
["- a\n - [ ] y\n - [ ] q", "- ay\n - [ ] q"],
77+
])("joins y in %j onto the line above", (value, expected) => {
78+
using editor = makeEditor(value);
79+
placeCaret(editor, "y");
80+
editor.commands.keyboardShortcut("Backspace");
81+
expect(storedDraft(editor)).toBe(expected);
82+
});
83+
84+
it("removes an empty checkbox under a bullet", () => {
85+
using editor = makeEditor("- a\n - [ ] x\n - [ ]");
86+
editor.view.dispatch(editor.state.tr.setSelection(TextSelection.atEnd(editor.state.doc)));
87+
editor.commands.keyboardShortcut("Backspace");
88+
expect(storedDraft(editor)).toBe("- a\n - [ ] x");
89+
});
7190
});
7291

7392
describe("blocks that a list item or quote cannot hold", () => {

‎apps/web/src/composer-rich-text-doc.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { joinBackward, joinTextblockBackward, joinTextblockForward } from "@tiptap/pm/commands";
1+
import { joinTextblockBackward, joinTextblockForward } from "@tiptap/pm/commands";
22
import {
33
Fragment,
44
Mark,
@@ -1135,7 +1135,8 @@ function backspaceAcrossList(editor: Editor): boolean {
11351135
return moved;
11361136
};
11371137
// can() skips the schema check and can accept tasks with no parent list to lift into.
1138-
return editor.chain().command(lift).run() || joinBackward(state, editor.view.dispatch);
1138+
// Those join the line above; joinBackward would re-nest them or select the parent line.
1139+
return editor.chain().command(lift).run() || joinTextblockBackward(state, editor.view.dispatch);
11391140
}
11401141
const before = $from.depth === 1 ? $from.node(0).maybeChild($from.index(0) - 1) : null;
11411142
if (before && LIST_NODE_NAMES.has(before.type.name) && $from.parent.type.name !== "codeBlock") {

0 commit comments

Comments
 (0)