Skip to content

Commit 868524f

Browse files
authored
fix(web): Backspace no longer re-nests a checkbox under a bullet (pingdotgg#27384)
1 parent cae3ced commit 868524f

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,
@@ -1203,7 +1203,8 @@ function backspaceAcrossList(editor: Editor): boolean {
12031203
return moved;
12041204
};
12051205
// can() skips the schema check and can accept tasks with no parent list to lift into.
1206-
return editor.chain().command(lift).run() || joinBackward(state, editor.view.dispatch);
1206+
// Those join the line above; joinBackward would re-nest them or select the parent line.
1207+
return editor.chain().command(lift).run() || joinTextblockBackward(state, editor.view.dispatch);
12071208
}
12081209
const before = $from.depth === 1 ? $from.node(0).maybeChild($from.index(0) - 1) : null;
12091210
if (before && LIST_NODE_NAMES.has(before.type.name) && $from.parent.type.name !== "codeBlock") {

0 commit comments

Comments
 (0)