Skip to content

Commit b2a9e93

Browse files
[lexical-table] Bug Fix: include first cell contents in partial backwards table selection (#7998)
1 parent fa854d0 commit b2a9e93

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/lexical-playground/__tests__/e2e/Selection.spec.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ test.describe.parallel('Selection', () => {
14991499
await assertSelection(page, {
15001500
anchorOffset: 0,
15011501
anchorPath: [2],
1502-
focusOffset: 1,
1502+
focusOffset: 0,
15031503
focusPath: [1, 1, 0],
15041504
});
15051505
});
@@ -1544,7 +1544,7 @@ test.describe.parallel('Selection', () => {
15441544
await assertSelection(page, {
15451545
anchorOffset: 0,
15461546
anchorPath: [1],
1547-
focusOffset: 1,
1547+
focusOffset: 0,
15481548
focusPath: [0, 1, 0],
15491549
});
15501550
},
@@ -1659,7 +1659,7 @@ test.describe.parallel('Selection', () => {
16591659
await assertSelection(page, {
16601660
anchorOffset: 0,
16611661
anchorPath: [2],
1662-
focusOffset: 1,
1662+
focusOffset: 0,
16631663
focusPath: [1, 1, 0],
16641664
});
16651665
});

packages/lexical-table/src/LexicalTableSelectionHelpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,11 +1045,11 @@ export function applyTableHandlers(
10451045
);
10461046
const firstCell = tableMap[0][0].cell;
10471047
const lastCell = tableMap[tableMap.length - 1].at(-1)!.cell;
1048+
// When backward, focus should be at START of first cell (0)
1049+
// When forward, focus should be at END of last cell (getChildrenSize)
10481050
newSelection.focus.set(
10491051
isBackward ? firstCell.getKey() : lastCell.getKey(),
1050-
isBackward
1051-
? firstCell.getChildrenSize()
1052-
: lastCell.getChildrenSize(),
1052+
isBackward ? 0 : lastCell.getChildrenSize(),
10531053
'element',
10541054
);
10551055
} else if (isAnchorInside) {

0 commit comments

Comments
 (0)