Skip to content
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

Paragraph contents move to previous paragraph when deleted #8638

Closed
iandunn opened this issue Aug 7, 2018 · 4 comments · Fixed by #8651
Closed

Paragraph contents move to previous paragraph when deleted #8638

iandunn opened this issue Aug 7, 2018 · 4 comments · Fixed by #8651
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Type] Bug An existing feature does not function as intended

Comments

@iandunn
Copy link
Member

iandunn commented Aug 7, 2018

Describe the bug

Sometimes attempting to delete the contents of a paragraph block sometimes will instead move the contents into the previous paragraph.

To Reproduce

  1. Create a new post, switch to Code Editor mode, and paste in the following sample. Then, switch back to Visual Mode.
<!-- wp:paragraph -->
<p>paragraph one.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>paragraph two.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>paragraph three.</p>
<!-- /wp:paragraph -->
  1. Highlight all of the text inside the block by clicking the mouse at the end of the text and dragging it to the beginning, by Command+Shift+Left, or by Shift+PageUp. Don't use Control+A, or start at the beginning of the line, or use the Delete key, because the bug isn't triggered in those scenarios.

  2. Hit the Backspace key to delete the paragraph.

Expected behavior

The contents of the block should be deleted. (Maybe the block itself should be deleted too, but I'm not really concerned about that.)

Actual behavior

Rather than the contents being deleted, they're moved into the previous paragraph, so that the raw document now looks like this:

<!-- wp:paragraph -->
<p>paragraph one.paragraph two.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>paragraph three.</p>
<!-- /wp:paragraph -->

Desktop (please complete the following information):

  • OS X 10.13.6
  • Chrome 67.0.3396.99
  • Gutenberg master @ 4fd5c20
@iandunn
Copy link
Member Author

iandunn commented Aug 7, 2018

Another symptom of the bug:

  1. Inside the second paragraph, highlight two by dragging the mouse from t to ., or by positioning the cursor at t and using Command+Shift+Right
  2. Hit delete

The text from paragraph two will not be deleted, and the text from paragraph three will be moved into paragraph two.

@noisysocks
Copy link
Member

Going to close this one as duplicate of #8639 since #8639 has some useful additional context.

@talldan
Copy link
Contributor

talldan commented Aug 7, 2018

Copying my comment from the other issue here and reopening (it's still pretty serendipitous that both were spotted at the same time!).


I think this one is actually slightly different, this is about content being merged when it should actually be deleted. My one is about nothing happening when hitting delete.

Pretty sure the same code is the culprit - it seems like the event is treated as a merge when it should be a remove. (the onMerge function is called before onRemove ):

if (
( keyCode === BACKSPACE && isHorizontalEdge( rootNode, true ) ) ||
( keyCode === DELETE && isHorizontalEdge( rootNode, false ) )
) {
if ( ! this.props.onMerge && ! this.props.onRemove ) {
return;
}
const forward = keyCode === DELETE;
if ( this.props.onMerge ) {
this.props.onMerge( forward );
}
if ( this.props.onRemove && this.isEmpty() ) {
this.props.onRemove( forward );
}
event.preventDefault();
// Calling onMerge() or onRemove() will destroy the editor, so it's important
// that we stop other handlers (e.g. ones registered by TinyMCE) from
// also handling this event.
event.stopImmediatePropagation();
}

@mraljabry
Copy link

hello, I'm having this same issue here. When I click backspace, it goes back to the previous paragraph. I'm not a programmer or anything so I'm confused if this issue is resolved or what exactly??

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... [Type] Bug An existing feature does not function as intended
Projects
None yet
4 participants