Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Fix selection when hitting "shift+arrowdown" into a table. #14

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Selection.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
});
});
11 changes: 9 additions & 2 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down