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

Removing a block(s) with keyboard selection + backspace/delete does not reflect on preview or publish #42213

Closed
vajrasar opened this issue Jul 7, 2022 · 7 comments
Labels
[Feature] Block Multi Selection The ability to select and manipulate multiple blocks [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended

Comments

@vajrasar
Copy link

vajrasar commented Jul 7, 2022

Description

The issue can be seen when a new post is created (with or without the Gutenberg plugin installed), and you try to remove some lines of text or paragraph by the method of selecting them (keyboard selection) and pressing backspace/delete. Those lines/para won't be deleted and you can see that in preview, and also when the post is published.

Step-by-step reproduction instructions

  1. Create a new post, and put some content on it.
  2. Say you have two consecutive blocks of text on the content that you want to remove.
  3. Place the cursor on the starting of the first line of text.
  4. Use the keyboard to select that line and the line below it.
  5. Use the backspace/delete button on keyboard to remove those lines.
  6. You should be able to see the expected change in editor.
  7. But checking preview, saving draft, and publishing the post won't show the change.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress version 6.0
  • Gutenberg version 13.6.0
  • Browser: Chrome 102.0.5005.115 (arm64)
  • Machine: M1 MBP

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@talldan talldan added [Type] Bug An existing feature does not function as intended [Priority] High Used to indicate top priority items that need quick attention labels Jul 8, 2022
@ramonjd
Copy link
Member

ramonjd commented Jul 8, 2022

Sounds like it's related to this comment by @youknowriad #38892 (comment) but for rich text blocks only.

cc @ellatrix

@talldan
Copy link
Contributor

talldan commented Jul 8, 2022

I think the problem might be that when selecting two blocks in this way, the editor doesn't seem to consider it a multi-selection. This is how the editor is supposed to look when two blocks are selected using the mouse (notice the block toolbar shows grouping buttons because the editor considers this a multi-block selection):
Screen Shot 2022-07-08 at 11 50 23 am

This is how it looks when following the reproduction steps (the grouping buttons aren't shown):
Screen Shot 2022-07-08 at 11 51 46 am

I think that because the editor doesn't consider this a multi-block selection, it doesn't properly delete the blocks when backspace or delete is pressed.

From what I can tell it's this bit of code that isn't working, it doesn't set the end selection when the second block is selected. I'm not sure what the right fix would be, it seems difficult to determine when the second block is selected versus when the whole of the first block is selected:

if (
element.contains( anchorNode ) &&
element !== anchorNode &&
element.contains( focusNode ) &&
element !== focusNode
) {
const { start, end } = createRecord();
record.current.activeFormats = EMPTY_ACTIVE_FORMATS;
onSelectionChange( start, end );
} else if (
element.contains( anchorNode ) &&
element !== anchorNode
) {
const { start, end: offset = start } = createRecord();
record.current.activeFormats = EMPTY_ACTIVE_FORMATS;
onSelectionChange( offset );
} else if (
element.contains( focusNode ) &&
element !== focusNode
) {
const { start, end: offset = start } = createRecord();
record.current.activeFormats = EMPTY_ACTIVE_FORMATS;
onSelectionChange( undefined, offset );
}

Hopefully @ellatrix has an idea 😄

@gziolo gziolo added the [Feature] Block Multi Selection The ability to select and manipulate multiple blocks label Jul 11, 2022
@alanjacobmathew
Copy link
Contributor

I think that because the editor doesn't consider this a multi-block selection

Also notice when selecting using keyboard, it doesn't get reflected on the list view

@alanjacobmathew
Copy link
Contributor

A few more issue related with this,
1: It doesn't always happen. Problem persists when I use the down arrow key and not the right arrow keys. If I select the very first character using the right key and rest using the down key, it works as expected.

2: Cases where the problem persist, after removing the blocks, once you click on the next block it automatically replaces that block to the first block

3: Doesn't happening always, when multiselecting. Note the list view selection in the video.
Multi Select
Here, in the first case, first 3 block weren't selected, but once the fourth block was selected, the entire set was selected.
In the second case, when the very last block was selected every other blocks were also selected.

@glendaviesnz
Copy link
Contributor

glendaviesnz commented Oct 4, 2022

I wasn't able to replicate this on GB trunk or 6.1 Beta - I also tried just using the down arrow as @alanjacobmathew suggested but got the same result:

keyboard-selection.mp4

@mcsf
Copy link
Contributor

mcsf commented Oct 4, 2022

I wasn't able to replicate this on GB trunk or 6.1 Beta

Indeed, this seems to only affect 6.0.x.

@talldan
Copy link
Contributor

talldan commented Oct 5, 2022

Same here. 🎉

Thanks for checking. I'll close the issue.

@talldan talldan closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2022
Repository owner moved this from Triage to Done in WordPress 6.1 Editor Tasks Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Multi Selection The ability to select and manipulate multiple blocks [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
No open projects
Development

No branches or pull requests

7 participants