Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(editor): keep Tab inside lists instead of escaping focus (MUL-3697) (#4605)

Naiyuan Qing714f9b1ab76a
diff --git a/packages/views/editor/extensions/list-item.test.ts b/packages/views/editor/extensions/list-item.test.ts
index acef310c83..7d2569c8af 100644
--- a/packages/views/editor/extensions/list-item.test.ts
+++ b/packages/views/editor/extensions/list-item.test.ts
@@ -270,11 +270,13 @@ describe("PatchedListItem Tab indent (MUL-3697)", () => {
const pressTab = (e: Editor) => pressShortcut(e, "listItem", "Tab");
- it("is a no-op with the cursor in the first item (nothing to nest under)", () => {
+ it("leaves the doc unchanged but swallows Tab in the first item (stay put, do not escape focus)", () => {
editor = makeEditor(flatList("bulletList", "listItem"));
editor.commands.setTextSelection(itemPos(editor, "listItem", 0));
- // C2: startIndex === 0 with a single item -> clean false, doc unchanged.
- expect(pressTab(editor)).toBe(false);
+ // Nothing to nest under, so the structural indent is a no-op — but the caret
+ // is in a list, so Tab is swallowed (true) instead of leaking to the browser
+ // and moving focus to other controls. The doc must be untouched.
+ expect(pressTab(editor)).toBe(true);
expect(outline(editor.getJSON() as JsonNode)).toBe("- aaa\n- bbb\n- ccc");
});
diff --git a/packages/views/editor/extensions/list-item.ts b/packages/views/editor/extensions/list-item.ts
index 2768787673..45ac3231f4 100644
--- a/packages/views/editor/extensions/list-item.ts
+++ b/packages/views/editor/extensions/list-item.ts
@@ -81,6 +81,14 @@ function sinkListItemRange(itemType: NodeType): Command {
*
* Tab indents the item(s) — see `sinkListItemRange` for the multi-item
* first-item handling. Shift-Tab dedents via the stock command.
+ *
+ * Whenever the caret is inside a list item, Tab is the list's indent control
+ * and must be swallowed even when the structural indent is a no-op (first child
+ * with nothing to nest under, or already at max depth). Otherwise the unhandled
+ * Tab falls through to the browser and moves focus out of the editor to the
+ * next control. So the return value tracks "is the caret in this list?"
+ * (`editor.isActive(name)`), NOT "did the indent move anything?": indent
+ * best-effort, then swallow while in a list, fall through (focus nav) when not.
*/
function listItemKeymap(editor: Editor, name: string) {
return {
@@ -92,9 +100,10 @@ function listItemKeymap(editor: Editor, name: string) {
Tab: () => {
const itemType = editor.schema.nodes[name];
if (!itemType) return false;
- return sinkListItemRange(itemType)(editor.state, (tr) =>
+ sinkListItemRange(itemType)(editor.state, (tr) =>
editor.view.dispatch(tr),
);
+ return editor.isActive(name);
},
"Shift-Tab": () => editor.commands.liftListItem(name),
};