Skip to content

Commit

Permalink
Revert "Revert "Fix #5720 update the resolvedOffset correctly on imag…
Browse files Browse the repository at this point in the history
…… …e selection and drag" (#5952)" (#5955)
  • Loading branch information
zurfyx authored Apr 24, 2024
1 parent 537054f commit 1f9352b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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

0 comments on commit 1f9352b

Please sign in to comment.