Skip to content

Inconsistent Copy/Cut Behavior Between Keyboard Shortcuts and Block Menu Actions #68941

Open
@yogeshbhutkar

Description

Description

Splitting it from here: #68554 (comment)

The behavior of the Copy (Cmd/Ctrl + C) and Cut (Cmd/Ctrl + X) actions varies depending on whether they are triggered via keyboard shortcuts or the block menu items.

I believe the above condition occurs because the content is set as both text/plain and text/html within the writing flow, and this change appears to be intentional.

event.clipboardData.setData( 'text/plain', toPlainText( serialized ) );
event.clipboardData.setData( 'text/html', serialized );
}

However, the Block Menu Items utilize the useCopyToClipboard hook, which only sets the content as text/plain (based on Clipboard.js). Therefore, to be consistent, we should set the data as both plain text and HTML on the clipboard to resolve this inconsistency.

const clipboard = new Clipboard( node, {
text() {
return typeof textRef.current === 'function'
? textRef.current()
: textRef.current || '';
},
} );

Please feel free to close this issue if it happens to be a duplicate of an existing issue.

Step-by-step reproduction instructions

  1. Select one or more Paragraph blocks.
  2. Copy or Cut using the block menu items from the three-dot menu.
  3. Paste the clipboard content into a text editor.
    3.1. Observe that the clipboard contains the full block markup.
  4. Now, repeat steps 1-3 using the keyboard shortcuts (Cmd/Ctrl + C or Cmd/Ctrl + X).
  5. Observe that only the block content (not the full markup) is copied.

Screenshots, screen recording, code snippet

bug.mov

Environment info

  • WordPress Version: 6.8-alpha-59361
  • Gutenberg Version: Latest Trunk
  • OS: macOS Sequoia

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block settings menuThe block settings screen[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions