Skip to content

Block Editor: Prevent block merging on blocks with the 'disabled' editing mode. #69918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2025

Conversation

jrmd
Copy link
Contributor

@jrmd jrmd commented Apr 16, 2025

What?

Closes #69915

This PR adds an additional check to the mergeBlocks action to prevent a block from being merged into a block that is disabled.

Why?

Blocks that are disabled shouldn't be able to be modified.

How?

Adds an extra check to the mergeBlocks action to check that the blocks current edit mode isn't disabled

Testing Instructions

Note

wp.data needs to be exposed to run the console command

  1. Create a post
  2. Add two paragraphs
  3. Open console run the following wp.data.dispatch('core/block-editor').setBlockEditingMode( wp.data.select('core/block-editor').getBlocks()[0].clientId, 'disabled')
  4. in the second paragraph put the cursor to the front of the block
  5. hit backspace
  6. see that the blocks aren't merged.

Screenshots or screencast

Before

Screen.Recording.2025-04-16.at.13.03.49.mov

After

Screen.Recording.2025-04-16.at.13.30.05.mov

This patch adds an additional check to the mergeBlocks action to prevent
a block from being merged into a block that is disabled.
@jrmd jrmd requested a review from ellatrix as a code owner April 16, 2025 12:49
Copy link

github-actions bot commented Apr 16, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

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: jrmd <jrmd@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 16, 2025
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @jrmd! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Block editor /packages/block-editor labels Apr 16, 2025
@Mamaduka Mamaduka self-requested a review April 16, 2025 12:58
@Mamaduka
Copy link
Member

Thanks for contributing, @jrmd!

I just realized that we also need to handle the forward delete case. Here are the reproduction steps:

  1. Add two paragraphs.
  2. Disable the second paragraph - wp.data.dispatch('core/block-editor').setBlockEditingMode( wp.data.select('core/block-editor').getBlocks()[1].clientId, 'disabled').
  3. Place a caret at the end of the first paragraph.
  4. Press forward delete. Fn+Delete on Mac.
  5. Expected: The disabled second block should be merged into the first block.
  6. Actual: The disabled second block is merged.

@jrmd
Copy link
Contributor Author

jrmd commented Apr 16, 2025

Ahh thanks @Mamaduka I actually tried to see if that test case was valid using the accessibility keyboard but it didnt work; so TIL about fn+delete :)

Updated the logic, and also added unit tests and fixed the failing unit tests :)

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing, @jrmd!

The fix works as expected ✅

@Mamaduka Mamaduka merged commit 913d9f5 into WordPress:trunk Apr 17, 2025
60 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.8 milestone Apr 17, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…ting mode. (WordPress#69918)

Co-authored-by: jrmd <jrmd@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting the block editor mode to disable should prevent block merging
2 participants