[lexical-clipboard] Bug Fix: $insertDataTransferForRichText ignores its selection argument for text/plain - #8974
Closed
LeSingh1 wants to merge 1 commit into
Closed
Conversation
…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
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 8, 2026 02:31
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default
text/plainimporter re-read$getSelection()for every token it inserted, so plain-text (andtext/uri-list) payloads always landed at the editor's current selection instead of theselectionargument that$insertDataTransferForRichTextdocuments as the insertion point. A caller that builds its ownRangeSelection— 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/htmlandapplication/x-lexical-editorhandlers already do via$insertGeneratedNodes.Five tests. Three fail without the change (
text/plainsingle-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