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 #5720 update the resolvedOffset correctly on image selection and drag #5795

Merged
merged 7 commits into from
Apr 1, 2024
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/Images.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -740,4 +740,51 @@ test.describe('Images', () => {
`,
);
});

test('Can resolve selection correctly when the image is clicked and dragged right', async ({
page,
isPlainText,
browserName,
isCollab,
}) => {
test.skip(isPlainText);
let leftFrame = page;
if (isCollab) {
leftFrame = await page.frame('left');
}
await focusEditor(page);

await page.keyboard.type('HelloWorld');
await insertSampleImage(page);
await click(page, '.editor-image img');

await leftFrame.locator('.editor-image img').hover();
await page.mouse.down();
await leftFrame.locator('.PlaygroundEditorTheme__paragraph').hover();
await page.mouse.up();
await waitForSelector(page, '.editor-image img');
await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">HelloWorld</span>
<span
class="editor-image"
contenteditable="false"
data-lexical-decorator="true">
<div draggable="false">
<img
alt="Yellow flower in tilt shift lens"
draggable="false"
src="${SAMPLE_IMAGE_URL}"
style="height: inherit; max-width: 500px; width: inherit" />
</div>
</span>
<br />
</p>
`,
);
});
});
4 changes: 4 additions & 0 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,10 @@ function internalResolveSelectionPoint(
return null;
}
if ($isElementNode(resolvedElement)) {
resolvedOffset = Math.min(
resolvedElement.getChildrenSize(),
resolvedOffset,
);
let child = resolvedElement.getChildAtIndex(resolvedOffset);
if (
$isElementNode(child) &&
Expand Down
Loading