diff --git a/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs b/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs index 22a15388f..a9178151e 100644 --- a/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs @@ -715,4 +715,24 @@ test.describe('Selection', () => { `, ); }); + + test('shift+arrowdown into a table selects the whole table', async ({ + page, + isPlainText, + isCollab, + }) => { + test.skip(isPlainText); + await focusEditor(page); + await insertTable(page, 2, 2); + await moveToEditorBeginning(page); + await page.keyboard.down('Shift'); + await page.keyboard.press('ArrowDown'); + await page.keyboard.up('Shift'); + await assertSelection(page, { + anchorOffset: 0, + anchorPath: [0], + focusOffset: 1, + focusPath: [1, 1, 1], + }); + }); }); diff --git a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts index 7d89e3fb9..e3392eeff 100644 --- a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts +++ b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts @@ -716,9 +716,16 @@ export function applyTableHandlers( if (isPartialyWithinTable) { const newSelection = selection.clone(); if (isFocusInside) { + const [tableMap] = $computeTableMap( + tableNode, + focusCellNode, + focusCellNode, + ); + const firstCellNode = tableMap[0][0].cell; + const lastCellNode = tableMap[tableMap.length - 1].at(-1)!.cell; newSelection.focus.set( - tableNode.getParentOrThrow().getKey(), - tableNode.getIndexWithinParent(), + (isBackward ? firstCellNode : lastCellNode).getKey(), + isBackward ? 0 : lastCellNode.getChildrenSize(), 'element', ); } else {