Skip to content

Fix: copy the text when the block's serialized content doesn't contain it - #84493

Open
prasadkarmalkar wants to merge 6 commits into
WordPress:trunkfrom
prasadkarmalkar:fix/84362-copy-bound-block-text
Open

prasadkarmalkar wants to merge 6 commits into
WordPress:trunkfrom
prasadkarmalkar:fix/84362-copy-bound-block-text

Conversation

@prasadkarmalkar

@prasadkarmalkar prasadkarmalkar commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #84362

Why?

How?

Add a new helper function isTextPreservedOnBlockCopy() in use-clipboard-handler.js, which is added as a condition to isWholeSingleBlockCopy:

  • It gets the text of serialize( block ) with stripHTML() and .trim(). This is the same text setClipboardBlocks() would put on the clipboard as text/plain.
  • If the DOM selection has text but the serialized block has none, the block copy would lose it. The handler then returns early, and the text copy handler copies the selected text as usual.

Testing Instructions

  1. Register a post meta field, for example in a mu-plugin:
    add_action( 'init', function () {
    	register_post_meta( 'post', 'test', array(
    		'label'        => 'Test field',
    		'single'       => true,
    		'type'         => 'string',
    		'show_in_rest' => true,
    		'default'      => 'Try to select and copy this text',
    	) );
    } );
  2. Create a post and add a paragraph bound to it through the code editor
  3. Click into the bound paragraph, select all of its text and copy it.
  4. Paste into another paragraph or an external text editor. The text should be pasted. On trunk, nothing is pasted.

Screenshots or screencast

Screen.Recording.2026-10-09.at.4.45.52.PM.mov

Use of AI Tools

Tool -> Claude Code
Model -> Opus 5.5
Use -> Research the issue and create a test case (all code manually verified and tested)

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Oct 10, 2026
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: prasadkarmalkar <prasadkarmalkar@git.wordpress.org>
Co-authored-by: umeshnevase <umeshnevase@git.wordpress.org>
Co-authored-by: wpbt <bharatthapa@git.wordpress.org>
Co-authored-by: dlh01 <dlh@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copying the block when its entire text is selected can prevent the text from being copied

1 participant