Skip to content

When using the delete key to remove blocks, the caret is positioned incorrectly #8965

@talldan

Description

@talldan

Describe the bug
When using backspace to delete blocks, the preceding block is correctly selected after the removal takes place.

However, when using the delete key, the behaviour is the same and the preceding block is still selected. To be consistent with how the delete key works normally when deleting text, the start of the next block should instead be selected

To Reproduce
Steps to reproduce the behavior:

  1. Create a new post
  2. Add four paragraphs of text
  3. Select the middle two paragraphs
  4. Press the delete key (you may need to use fn+backspace on a laptop)
  5. Observe that the caret is placed in the first block

Expected behavior
The caret is positioned at the start of the last block

Additional context

  • Gutenberg 3.5
  • The code that handles the delete event is in the component EditorGlobalKeyboardShortcuts (this seems to be triggered for multi-selection) or BlockListBlock (when there's only a single block selected). Currently, they trigger the removeBlocks action, but the removeBlocks is not passed any data about the direction of the delete event. Delete and Backspace are both handled in the same way.
  • It would be beneficial to add test cases to the block-deletion e2e test when fixing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Writing FlowBlock selection, navigation, splitting, merging, deletion...[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions