diff --git a/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs b/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs index 71bba6fa5da..38aac924f35 100644 --- a/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/Selection.spec.mjs @@ -578,6 +578,53 @@ test.describe.parallel('Selection', () => { ); }); + test('Can adjust tripple click selection with', async ({ + page, + isPlainText, + isCollab, + }) => { + test.skip(isPlainText || isCollab); + + await pasteFromClipboard(page, { + 'text/html': `
Helloworld
!
`, + }); + + await page + .locator('div[contenteditable="true"] > p') + .first() + .click({clickCount: 3}); + + await pressToggleBold(page); + + await assertHTML( + page, + html` ++ + + Hello + + + + world + +
++ ! +
+ `, + ); + }); + test('Select all from Node selection #4658', async ({page, isPlainText}) => { // TODO selectAll is bad for Linux #4665 test.skip(isPlainText || IS_LINUX); diff --git a/packages/lexical/src/LexicalEvents.ts b/packages/lexical/src/LexicalEvents.ts index 4ac619adbeb..092e06e6f4d 100644 --- a/packages/lexical/src/LexicalEvents.ts +++ b/packages/lexical/src/LexicalEvents.ts @@ -77,6 +77,7 @@ import { } from './LexicalSelection'; import {getActiveEditor, updateEditorSync} from './LexicalUpdates'; import { + $findMatchingParent, $flushMutations, $getNodeByKey, $isSelectionCapturedInDecorator, @@ -189,7 +190,6 @@ let collapsedSelectionFormat: [number, string, number, NodeKey, number] = [ // work as intended between different browsers and across word, line and character // boundary/formats. It also is important for text replacement, node schemas and // composition mechanics. - function $shouldPreventDefaultAndInsertText( selection: RangeSelection, domTargetRange: null | StaticRange, @@ -447,10 +447,12 @@ function onClick(event: PointerEvent, editor: LexicalEditor): void { const focus = selection.focus; const focusNode = focus.getNode(); if (anchorNode !== focusNode) { - if ($isElementNode(anchorNode)) { - anchorNode.select(0); - } else { - anchorNode.getParentOrThrow().select(0); + const parentNode = $findMatchingParent( + anchorNode, + (node) => $isElementNode(node) && !node.isInline(), + ); + if ($isElementNode(parentNode)) { + parentNode.select(0); } } }