From 04d60251e0371380b97457024424690d1e74271b Mon Sep 17 00:00:00 2001 From: Matthew Lipski Date: Wed, 3 Jun 2026 17:27:52 +0200 Subject: [PATCH] Made pressing Tab/Shift+Tab at the end/start cell of a table no-op --- .../core/src/blocks/Table/TableExtension.ts | 26 +++++++++++++----- tests/src/end-to-end/tables/tables.test.ts | 27 +++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/packages/core/src/blocks/Table/TableExtension.ts b/packages/core/src/blocks/Table/TableExtension.ts index 1d2cf9d47f..4ddeb56ce8 100644 --- a/packages/core/src/blocks/Table/TableExtension.ts +++ b/packages/core/src/blocks/Table/TableExtension.ts @@ -84,14 +84,28 @@ export const TableExtension = Extension.create({ }, // Enables navigating cells using the tab key. Tab: () => { - return this.editor.commands.command(({ state, dispatch, view }) => - goToNextCell(1)(state, dispatch, view), - ); + return this.editor.commands.command(({ state, dispatch, view }) => { + if (!isInTable(state)) { + return false; + } + + goToNextCell(1)(state, dispatch, view); + + // Always return true to avoid accidental indents. + return true; + }); }, "Shift-Tab": () => { - return this.editor.commands.command(({ state, dispatch, view }) => - goToNextCell(-1)(state, dispatch, view), - ); + return this.editor.commands.command(({ state, dispatch, view }) => { + if (!isInTable(state)) { + return false; + } + + // Always return true to avoid accidental un-indents. + goToNextCell(-1)(state, dispatch, view); + + return true; + }); }, }; }, diff --git a/tests/src/end-to-end/tables/tables.test.ts b/tests/src/end-to-end/tables/tables.test.ts index caed60b14a..7cba2b3541 100644 --- a/tests/src/end-to-end/tables/tables.test.ts +++ b/tests/src/end-to-end/tables/tables.test.ts @@ -3,6 +3,7 @@ import { test } from "../../setup/setupScript.js"; import { BASE_URL, TABLE_SELECTOR } from "../../utils/const.js"; import { compareDocToSnapshot, focusOnEditor } from "../../utils/editor.js"; import { executeSlashCommand } from "../../utils/slashmenu.js"; +import { insertParagraph } from "../../utils/copypaste.js"; test.beforeEach(async ({ page }) => { await page.goto(BASE_URL); @@ -32,6 +33,32 @@ test.describe("Check Table interactions", () => { await compareDocToSnapshot(page, "tabCells.json"); }); + test("Tab in last cell should be a no-op", async ({ page }) => { + await focusOnEditor(page); + + await insertParagraph(page); + await executeSlashCommand(page, "table"); + + for (let i = 0; i < 6; i++) { + await page.keyboard.press("Tab"); + } + + // Only top level block group should exist. + await expect(page.locator(".bn-block-group")).toHaveCount(1); + }); + test("Shift+Tab in first should be a no-op", async ({ page }) => { + await focusOnEditor(page); + + await insertParagraph(page); + await page.keyboard.press("Enter"); + await page.keyboard.press("Tab"); + await executeSlashCommand(page, "table"); + + await page.keyboard.press("Shift+Tab"); + + // Block group containing table should exist as well as top level group. + await expect(page.locator(".bn-block-group")).toHaveCount(2); + }); test("Arrow keys should move cells", async ({ page }) => { await focusOnEditor(page); await executeSlashCommand(page, "table");