gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Pressing backspace at the start of a paragraph block before a classic text block causes the classic text block to be deleted

Open BoardJames opened this issue 9 years ago • 7 comments

Issue Overview

It appears the merging logic has a problem with merging a paragraph block into an existing classic text block (aka freeform). If you press backspace at the start of a paragraph block that is directly after a classic text block then instead of merging with the classic text block it deletes the classic text block.

Steps to Reproduce (for bugs)

  1. Create a paragraph block with identifiable content
  2. Create a classic text block with identifiable content
  3. Create a paragraph block with identifiable content
  4. Position cursor at the start of the last paragraph block
  5. Press backspace

Expected Behavior

I expect that either the merge will be rejected and nothing will happen or that the paragraph block following the classic text block will be appended at the end of the classic text block.

Current Behavior

The classic text block is deleted and the cursor is placed at the end of the first paragraph block. The second paragraph block remains unchanged.

classic-text-merge-bug

BoardJames avatar Aug 28 '17 04:08 BoardJames

When I try to pause the merge in the debugger I can't replicate the problem!

BoardJames avatar Aug 28 '17 05:08 BoardJames

Right, after a frustrating debugging session I think the cause is thus:

  1. The user presses the backspace key down.
  2. The key down event triggers the MERGE_BLOCKS handler in editor/effects.js
  3. The MERGE_BLOCKS handler fails to convert the block so it falls back to just focusing the previous block
  4. The focus of the classic text block succeeds
  5. The user releases the backspace key
  6. The onKeyUp handler on the calls removeOrDeselect which detects the backspace and decides that the user is trying to delete the block and calls onRemove
  7. The classic text block is removed

BoardJames avatar Aug 28 '17 06:08 BoardJames

@iseulde Is there any reason why the removeOrDeselect function could not be run onKeyDown instead of onKeyUp?

BoardJames avatar Aug 28 '17 06:08 BoardJames

@youknowriad or @aduth do you know if there is a reason that removeOrDeselect (in editor/modes/visual-editor/block.js) needs to run on the key up handler? Could it be run on the key down handler to fix this bug?

BoardJames avatar Aug 29 '17 05:08 BoardJames

I think we could try onKeyDown if it's not causing any other issue

youknowriad avatar Aug 29 '17 09:08 youknowriad

Ok, I will put in a pull request with the change. My tests did not show any obvious problems but it seemed that it had been put in the onKeyUp handler deliberately.

BoardJames avatar Aug 30 '17 04:08 BoardJames

PR: https://github.com/WordPress/gutenberg/pull/2599

BoardJames avatar Aug 30 '17 05:08 BoardJames