Skip to content

Commit

Permalink
Bug Fix: Fix issue where triple-clicking a cell would dangerously sel…
Browse files Browse the repository at this point in the history
…ect entire document (facebook#6542)
  • Loading branch information
moughxyz authored Aug 22, 2024
1 parent fd7a93d commit 4b646a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
32 changes: 32 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Selection.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,38 @@ test.describe.parallel('Selection', () => {
);
});

test('Triple-clicking last cell in table should not select entire document', async ({
page,
isPlainText,
isCollab,
browserName,
legacyEvents,
}) => {
test.skip(isPlainText);

await focusEditor(page);
await page.keyboard.type('Line1');
await insertTable(page, 1, 2);

const lastCell = page.locator(
'.PlaygroundEditorTheme__tableCell:last-child',
);
await lastCell.click();
await page.keyboard.type('Foo');

const lastCellText = lastCell.locator('span');
const tripleClickDelay = 50;
await lastCellText.click({clickCount: 3, delay: tripleClickDelay});

// Only the last cell should be selected, and not the entire docuemnt
await assertSelection(page, {
anchorOffset: 0,
anchorPath: [1, 0, 1, 0],
focusOffset: 1,
focusPath: [1, 0, 1, 0],
});
});

test('Can persist the text format from the paragraph', async ({
page,
isPlainText,
Expand Down
8 changes: 0 additions & 8 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,6 @@ export function applyTableHandlers(
: lastCell.getChildrenSize(),
'element',
);
} else {
newSelection.anchor.set(
tableNode.getParentOrThrow().getKey(),
isBackward
? tableNode.getIndexWithinParent() + 1
: tableNode.getIndexWithinParent(),
'element',
);
}
$setSelection(newSelection);
$addHighlightStyleToTable(editor, tableObserver);
Expand Down

0 comments on commit 4b646a1

Please sign in to comment.