Skip to content

Commit 661a3e2

Browse files
fix(web): Backspace right after a list shortcut keeps the typed marker (pingdotgg#34802)
1 parent 18866e5 commit 661a3e2

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎apps/web/src/composer-block-shortcuts.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,31 @@ describe("composer list normalization", () => {
316316
expect(editor.state.doc.textContent).toBe("- go");
317317
});
318318

319+
it.each([
320+
["+ ", "bulletList"],
321+
["* ", "bulletList"],
322+
["1. ", "orderedList"],
323+
])("keeps the typed %j when Backspace follows its list shortcut", (marker, list) => {
324+
const editor = createEditor("");
325+
for (const char of marker) {
326+
const { from, to } = editor.state.selection;
327+
const insert = () => editor.state.tr.insertText(char, from, to);
328+
const handled = editor.state.plugins.some((plugin) =>
329+
plugin.props.handleTextInput?.call(plugin, editor.view, from, to, char, insert),
330+
);
331+
if (!handled) editor.view.dispatch(editor.state.tr.insertText(char, from, to));
332+
}
333+
expect(editor.state.doc.firstChild?.type.name).toBe(list);
334+
const backspace = chord("Backspace");
335+
expect(
336+
editor.state.plugins.some((plugin) =>
337+
plugin.props.handleKeyDown?.call(plugin, editor.view, backspace),
338+
),
339+
).toBe(true);
340+
expect(editor.state.doc.firstChild?.type.name).toBe("paragraph");
341+
expect(editor.state.doc.textContent).toBe(marker);
342+
});
343+
319344
it("preserves formatting and the caret when removing the literal prefix", () => {
320345
const editor = createEditor("**text**");
321346
editor.view.dispatch(editor.state.tr.insert(1, editor.schema.text("- ")));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ const ComposerListItemExtension = ListItem.extend({
486486
addKeyboardShortcuts() {
487487
return {
488488
...withoutBlockChords(this.parent?.(), LIST_NESTING_KEYS),
489-
Backspace: () => backspaceAcrossList(this.editor),
489+
// Replacing Tiptap's Backspace drops its undoInputRule, which keeps a just-typed "+ " literal.
490+
Backspace: () => this.editor.commands.undoInputRule() || backspaceAcrossList(this.editor),
490491
Delete: () => deleteAcrossList(this.editor),
491492
};
492493
},

0 commit comments

Comments
 (0)