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

fix: triple click around inline elements (links) #7055

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
47 changes: 47 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Selection.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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': `<p><a href="https://test.com">Hello</a>world</p><p>!</p>`,
});

await page
.locator('div[contenteditable="true"] > p')
.first()
.click({clickCount: 3});

await pressToggleBold(page);

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<a
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr"
href="https://test.com">
<strong
class="PlaygroundEditorTheme__textBold"
data-lexical-text="true">
Hello
</strong>
</a>
<strong
class="PlaygroundEditorTheme__textBold"
data-lexical-text="true">
world
</strong>
</p>
<p class="PlaygroundEditorTheme__paragraph">
<span data-lexical-text="true">!</span>
</p>
`,
);
});

test('Select all from Node selection #4658', async ({page, isPlainText}) => {
// TODO selectAll is bad for Linux #4665
test.skip(isPlainText || IS_LINUX);
Expand Down
12 changes: 7 additions & 5 deletions packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
} from './LexicalSelection';
import {getActiveEditor, updateEditorSync} from './LexicalUpdates';
import {
$findMatchingParent,
$flushMutations,
$getNodeByKey,
$isSelectionCapturedInDecorator,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Loading