From eadf0f9c6eb98b43d1137f41c056ba2d4880fb8f Mon Sep 17 00:00:00 2001 From: Serey Roth Date: Fri, 7 Jun 2024 15:21:03 -0700 Subject: [PATCH 1/2] Fix selection when hitting "shift+arrowdown" into a table. Previously, the selection included only up to the first cell and its children, even though the whole table appears selected. We update the logic so that the entire table will actually be selected. --- .../__tests__/e2e/Selection.spec.mjs | 20 +++++++++++++++++++ .../src/LexicalTableSelectionHelpers.ts | 11 ++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) 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 { From 58f7fdb383f044085c58bca20921352dbfb8aa80 Mon Sep 17 00:00:00 2001 From: "local-dev-korbit-ai-mentor[bot]" <130798245+local-dev-korbit-ai-mentor[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:39:11 +0000 Subject: [PATCH 2/2] [skip ci]