Skip to content

[lexical-clipboard] Bug Fix: $insertDataTransferForRichText ignores its selection argument for text/plain - #8974

Closed
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/6278-insert-data-transfer-selection
Closed

[lexical-clipboard] Bug Fix: $insertDataTransferForRichText ignores its selection argument for text/plain#8974
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/6278-insert-data-transfer-selection

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

The default text/plain importer re-read $getSelection() for every token it inserted, so plain-text (and text/uri-list) payloads always landed at the editor's current selection instead of the selection argument that $insertDataTransferForRichText documents as the insertion point. A caller that builds its own RangeSelection — a find-and-replace pass, say — had its content inserted at the caret.

The re-read exists for a reason: each insertion reports its trailing caret position through the editor's selection, and a node replacement can swap the selection object outright (#5954), so a held reference goes stale after the first token. Rather than drop the argument, promote it to the editor's selection before the loop. When the argument already is the editor's selection — every paste and drop — the behaviour is byte-for-byte unchanged, and insertion leaves the selection after the inserted content exactly as the text/html and application/x-lexical-editor handlers already do via $insertGeneratedNodes.

Five tests. Three fail without the change (text/plain single-line, multi-line, text/uri-list); two are marked in-source as controls that pass either way — text/html, which already honoured the argument, and the ordinary paste path where the argument is the current selection.

Fixes #6278

…ts selection argument for text/plain

The default `text/plain` importer re-read `$getSelection()` for every
token it inserted, so plain-text (and `text/uri-list`) payloads always
landed at the editor's current selection instead of the `selection`
argument that `$insertDataTransferForRichText` documents as the
insertion point. Callers that build their own RangeSelection — a
find-and-replace pass, for instance — had their content inserted at the
caret instead.

The re-read exists because each insertion reports its trailing caret
position through the editor's selection, and a node replacement can swap
the selection object outright (facebook#5954), so a held reference goes stale
after the first token. Promote the supplied selection to the editor's
selection before the loop instead of dropping it, which keeps the
existing paste/drop path byte-for-byte identical and matches what the
`text/html` and `application/x-lexical-editor` handlers already do via
`$insertGeneratedNodes`.

Fixes facebook#6278
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 8, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9052 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: $insertDataTransferForRichText doesn't use selection parameter

1 participant