Skip to content

Fix cursor position during forward delete of empty blocks#77525

Open
dpmehta wants to merge 1 commit intoWordPress:trunkfrom
dpmehta:fix/forward-delete-from-empty-block-issue
Open

Fix cursor position during forward delete of empty blocks#77525
dpmehta wants to merge 1 commit intoWordPress:trunkfrom
dpmehta:fix/forward-delete-from-empty-block-issue

Conversation

@dpmehta
Copy link
Copy Markdown
Contributor

@dpmehta dpmehta commented Apr 21, 2026

What?

Closes #64235

Fixes an issue where the cursor incorrectly moves to the end of the preceding block when forward-deleting an empty paragraph, instead of moving into the following block.

Note : It is already tested that this issue only happening with paragraph block as it is default block, i have tested with heading block as well in that issue does not happen for it cursor correctly moves to beginning of third heading.

Why?

When performing a "Forward Delete" at the end of a block, a forward merge is triggered. If the current block is an "unmodified default block" (like an empty Paragraph), the mergeBlocks action removes it.

Previously, this removal defaulted to moving the selection to the previous block. For a Backspace (reverse merge), this makes sense, but for a Forward Delete, where the user wants to go to the next block, it doesn't.

How?

In packages/block-editor/src/store/actions.js, the mergeBlocks logic has been updated for unmodified default blocks. When a forward merge is triggered and the block being removed is the currently selected one, the action now explicitly selects the next block (clientIdB) at the start position (offset 0), ensuring the cursor moves forward rather than backward.

Testing Instructions

  1. Create three Paragraph blocks with some text.
  2. Place the cursor at the beginning of the second paragraph.
  3. Delete the text in the second paragraph character by character using Forward Delete (Fn + Delete on Mac).
  4. Once the second paragraph is empty, press Forward Delete one more time.
  5. Verify: The cursor should move to the beginning of the third paragraph.
  6. Verify: It should not jump to the end of the first paragraph.
  7. Repeat the test with Heading blocks to ensure no regressions (Headings should already work correctly as they are not default blocks).

Screenshots or screencast

Before Fix :

before-fix

After Fix

after-fix

Use of AI Tools

AI ( Gemini 3.1 Pro ) was used to trace the mergeBlocks action logic and draft this PR description.

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Apr 21, 2026
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels Apr 21, 2026
@dpmehta dpmehta marked this pull request as ready for review April 21, 2026 14:28
@dpmehta dpmehta requested a review from ellatrix as a code owner April 21, 2026 14:28
@github-actions
Copy link
Copy Markdown

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: dpmehta <mehtadev@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

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

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

Labels

[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [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.

Forward delete from empty block selects previous block

2 participants