Skip to content

Gutenberg cross-block selection #3629

Closed

Description

@atimmer

Cross-block selection is something that is absolutely necessary because every editor has this. In any location on any computing device, it is possible to select across paragraphs. Breaking this would be a huge break in users expectations.

Problem

Because Gutenberg has chosen for separating blocks into multiple editors this isn't easily achievable. Browsers don't support multiple selections/focuses. When you are in one editable field you cannot be in another one. Editable fields include inputs, textareas and contenteditable elements. So we need to work around this in a different way.

Solution approach

The only way to solve this while keeping paragraphs in different blocks is by removing the contenteditable property by default from all blocks. This property needs to be re-added once edit intent is shown.

Edit intent can be the following things:

  • Clicking and releasing a block.
  • Touching and releasing a block.
  • Focusing a block using the keyboard.

The big advantages of this are when selecting over multiple blocks the user is just selecting HTML. So selecting content works in exactly the same way as you'd expect.

There is of course behaviour that is hard to (re-)implement with this model. When you press SHIFT+Arrow down in a block it selects text. When you reach the end of the block you want the selection to continue to the next block. So at this point the block needs to lose it's contenteditable property and the selection re-applied. Because the browser also supports SHIFT+Arrow down on a selection on HTML we don't have to do anything else. This could also be solved by removing the contenteditable property as soon as you start selecting. The browser's default selection mechanisms would handle all the rest.

Other behavior includes pressing keys when you have selected HTML. When you press ENTER you expect the selected content to be deleted. Given that we already control a lot of the keys in Gutenberg I don't see this as a really big problem.

Expected Behavior

I can select text over multiple blocks.

Current Behavior

I can only select the blocks themselves.

Todos

  • Tests
  • Documentation

Activity

  1. ephox-mogran commented on Nov 24, 2017

    @ephox-mogran
    Contributor

    Because the browser also supports SHIFT+Arrow down on a selection on HTML we don't have to do anything else. This could also be solved by removing the contenteditable property as soon as you start selecting. The browser's default selection mechanisms would handle all the rest.

    This is browser-dependent. Firefox and Chrome provide support for Shift+arrows in non content-editable environments, but IE and Edge do not appear to (from previous experience). I have two fiddles to show this:

    https://jsfiddle.net/bzf5vy9u/1/

    https://jsfiddle.net/bzf5vy9u/3/

    The second fiddle wraps the entire area inside a div with tabindex just in case there was an issue with the keyboard focus not being set.

    If you try and do a ranged selection between the bottom two paragraphs (normal p tags with no content editable attribute) you will notice (at least in my testing) that IE and Edge do not change the selection. Therefore, you would have to implement this yourself.

    It is possible to implement this yourself, obviously, but it can be quite complicated. The streamlined content possibilities in WordPress at the moment will help (not having different font sizes inside the content, not floating images with text etc.), but there will still be challenges. You'll also be using some APIs which can be very browser-dependent. Be aware that this may not be as simple as you would like.

    Other behavior includes pressing keys when you have selected HTML. When you press ENTER you expect the selected content to be deleted. Given that we already control a lot of the keys in Gutenberg I don't see this as a really big problem.

    Any key press would be expected to replace the current selection with the inserted key. This will need to handle capitalised keys (and potentially IMEs), so you'll essentially have to make sure you are covering all input sources (also pasting), some of which won't be known until keypress instead of keydown (due to how shift changes them). You'll probably need to use the Range APIs and call deleteContents or insertNode etc, but you are once again going to hit potential differences within browsers (for complex content). Browsers can choose to represent selections around images and other non-text nodes differently. Also, some might select into a bold tag and others might not. Just be aware that to get finely polished behaviour can take a long time. As soon as Gutenberg blocks are no longer tightly controlled, the edge cases might become a lot harder to identify. Also, if you expect ranged selections to move into the Classic Text block, then you'll need to solve the problem of complex content ranges. This also goes for partial selections into tables, lists etc.

    So in summary, don't underestimate how difficult this might be to get it right.

  2. anna-harrison commented on Nov 24, 2017

    @anna-harrison

    FYI: A really high level description of differences between browser selection models with some examples are in this blog post we wrote earlier this year

  3. atimmer commented on Nov 24, 2017

    @atimmer
    MemberAuthor

    @ephox-mogran Thank you for the comprehensive overview. It’s good to have all this context in one place.

  4. jasmussen commented on Nov 24, 2017

    @jasmussen
    Contributor

    Hi @atimmer, thanks for your thoughts.

    Gutenberg has cross-block selection, just not the way you're used to from plain text editors. In this case, we've chosen to go the block editor route, not the text editor route.

    There are a laundry list of pros and cons to either approach, which is why the Gutenberg project started with a 3 month phase where we tried both approaches. One prototype was the "single-instance" approach, where blocks were nested inside a single contenteditable field. The other prototype took the "multi instance" approach, which we ended up going with. The prototypes we decided between are no longer online, though they are buried in this repository somewhere if you look deep enough. Though a variant of the single instance approach can still be found here.

    It was very difficult to make a choice between the two, because both approaches have their merits and downsides.

    In case of the multi instance approach, there were clear benefits to how much easier it would be for plugin developers to create their own elaborate blocks, without worrying about affecting the surrounding blocks. It also embraced the block-level nature of the web in a way that was conducive to a contextual toolbar: when you select a paragraph, any alignment you give it applies to the block level, i.e. the entire block. When you select an image block, we don't show a "Bold" button, because that would have no effect on an image.

    The downsides are obvious too, you can't start a selection in the middle of one paragraph and end it in the middle of another. Instead you select both blocks, no matter if you selected using the keyboard or the mouse.

    In the case of the single instance approach, the chief benefits were that you could do exactly that — you could start and end a selection in the middle of paragraphs, and perhaps delete that to unify two paragraphs into one. On the other hand, you could make an image bold without knowing it. More problematic for an editor that was meant to gain a slew of new layout features was that with a single large content field, it was much more easy to make selections that were not actionable — if you selected some text from a caption and went too far and selected some of the paragraph block afterwards. Or when you have columns and grids, selecting ranges across blocks would also be a nightmare. When you can act on selections spanning multiple containers, it is a lot easier to end up with tag soup and the whole thing is less resilient.

    In our block editor not only is such tag soup and stray unclosed elements confined and sandboxed to a single block, but we can detect them at the block level and offer ways to solve it.

    In the end we made a decision back in March to go with the multi instance approach, acknowledging all the trade-offs that came with this decision. We felt the benefits outweighed the downsides.

    To your proposal in question, we did actually try a "contenteditable" hack, where as soon as you started selecting across blocks, the contenteditable property is applied to the parent container, letting you select HTML. It's possible, but it's not simple to do, and in the end the benefits of being able to delete the text between two paragraphs in order to merge them did not seem huge.

    On the flipside, this hack would prevent us from creating the multi-selection actions we are exploring now, and will also prevent plugins from hooking into that using simple Gutenberg APIs (see #3434 for context). For example, right now you can select 5 images and click a toolbar button to create a gallery of those. Or if you select 10 paragraphs, you can make it into a list or a quote. You can easily imagine a plugin registering a transformation that applies to one or several block types — say you could have a plugin block that registered itself as being able to convert multiple selected images into a slideshow.

    Having multiple paragraphs within a block could still be a preferred experience for some, though it also removes the ability of having block level controls at the granularity of the paragraph — movers, customization, drop-cap, etc. One of the first few versions of the plugin allowed you to keep multiple paragraphs if desired, or break out of them at will. It was considered too complicated, but we could revisit.

    In the end what we're building here is not just an editor. It's an editor, and also desktop publishing for the web. Some tradeoffs have to be made in order for other benefits to present themselves. I say this only as context for how we got to where we are today.

  5. JJJ commented on Dec 20, 2017

    @JJJ
    Contributor

    The problem (as I see it) with the current iteration is that the per-block editing decision isn't obvious, and users who try to highlight multiple blocks in a conventional click and drag type of way are greeted with something like this:

    screen shot 2017-12-20 at 1 28 31 pm

    I see 2 highlights:

    • Blue background is the highlight color in WordPress
    • Grey background is the highlight color in Safari

    I have 2 flow problems:

    • I don't know what to expect in my clipboard when I cut/copy
    • I don't know what more dragging & dropping will result in

    I have 2 confidence problems:

    • I don't know why something that works pretty-much everywhere else does not work here
    • I haven't learned anything, and am still not sure how to complete the original task

    I think we could improve this with some clever user-select CSS rules to prevent the grey background from appearing, and that might be enough for v1, but I tend to agree with @atimmer that the penultimate goal should be, eventually, to invent a way to shift-click or drag-target multiple blocks, and have the block-editor show the intersection of block properties and all that fun stuff.

  6. karmatosed commented on Jan 3, 2018

    @karmatosed
    Member

    @rosswintle has this to say in #4222:

    This is an/my opinion. I've searched a few pages of issues to see if it's anywhere else, but I couldn't find anything in the pages that I looked at (and there were a lot to wade through).

    I've been using Gutenberg today to write a big post with lots of paragraphs. I did it partly on an iPad, and then, in frustration, switched to my desktop.

    My opinion is this: having every paragraph as a separate block is confusing and creates too much pop-up user-interface/controls.

    This was hard on an iPad because the combination of taps required to select some text in a different paragraph was really tricky (and it's different to selecting text in a different paragraph then it is to select text in the current paragraph), and just because there were so many controls appearing and disappearing as I moved around that it really got in the way of the writing experience.

    I find myself wondering why every paragraph needs to be a block, and whether multi-paragraph blocks were tried at any point and rejected?

  7. aduth commented on Jan 10, 2018

    @aduth
    Member

    Related: #179

  8. aduth commented on Jan 10, 2018

    @aduth
    Member

    Related: #3696

  9. added
    Browser IssuesIssues or PRs that are related to browser specific problems
    on Jan 26, 2018
  10. jeffpaul commented on Jan 26, 2018

    @jeffpaul
    Member

    This ticket was mentioned in Slack in #core-editor by jeffpaul. View the logs.

  11. added this to the WordPress 5.0 milestone on Jun 4, 2018
  12. mcsf commented on Jul 16, 2018

    @mcsf
    Contributor

    As I close #179, I'm attaching this comment here in case the linked demo proves useful:

    #179 (comment)

  13. getsource commented on Oct 11, 2018

    @getsource
    Member

    Commenting here because I realized I hadn't left the feedback directly yet.

    Not being able to select text across blocks (with the keyboard, for example) is a problem that I run into nearly every time I write or edit a post with Gutenberg.

    Because this is a regression from the current editor, should it have the Backwards Compatibility label, or is there a different/better designation?

  14. removed this from the WordPress 5.0 milestone on Oct 11, 2018
  15. 6 remaining items

  16. JJJ commented on Oct 15, 2018

    @JJJ
    Contributor

    To me this seems like a basic and expected function in a text editor

    ...and...

    It's odd to me that I feel like I need to prove it

    ...get huge +1's from me.

    Needing to state these obvious things appears like feigned ignorance. It may not be, but it certainly feels that way on the other side of this. (Not that there's "sides" but hopefully you get my meaning.)

    At the risk of stating more obvious things, text editors are for quickly and easily editing text. Maybe it's just that Gutenberg isn't a text editor anymore? Even if that's true, that means willfully and intentionally abandoning literally everyone that uses WordPress for writing and editing, which feels like a mistake.

    Yes, people expect a fancier, more powerful editing experience, but that shouldn't come at the cost of removing every single other thing that people are used to doing almost everywhere else where a textbox has existed since the beginning of GUI computing.

  17. getsource commented on Oct 17, 2018

    @getsource
    Member

    @mtias reached out to me to chat directly about this, and I wanted to relay (after his okay) some of the conclusion of that back to the ticket.

    My understanding from him is that he'd be open to someone implementing and proposing a solution for this prior to 5.0, but it's not currently high enough priority to be a blocker.

    One of the important aspects of this, and I agree entirely, is that a solution to this problem should not make the user experience worse for users who are intending to select entire blocks.

    I don't think I know enough about the internals involved here to do so before 5.0, but would love if anyone for whom this bug is important could help out, since I think it'd help users out during the transition to Gutenberg.

  18. chrisvanpatten commented on Oct 17, 2018

    @chrisvanpatten
    Contributor

    I wonder if this could be tied into the Unified Toolbar option, so you get cross-block selection when that's enabled? It provides a "writing style" mode and this could be added there.

  19. getsource commented on Oct 17, 2018

    @getsource
    Member

    Ooo. I like that idea @chrisvanpatten. Especially if it looks like user needs will conflict.

  20. added
    [Feature] Writing FlowBlock selection, navigation, splitting, merging, deletion...
    and removed
    Browser IssuesIssues or PRs that are related to browser specific problems
    on Oct 22, 2018
  21. designsimply commented on Dec 20, 2018

    @designsimply
    Member

    Closed #13026 as a duplicate and wanted to include the video and a note from that report.

    My biggest difficulty with Gutenberg is that selecting and manipulating text is awkward -- I see different behaviors depending on where my mouse is located when I start to drag and select text on the screen. See the attached video -- different behaviors occur when:

    -My mouse is hovering over the title or a blank block.
    -My mouse is hovering over the left margin.
    -My mouse is inside a block with text.

    13026-27s

  22. added
    [Feature] Writing FlowBlock selection, navigation, splitting, merging, deletion...
    and removed
    [Feature] Writing FlowBlock selection, navigation, splitting, merging, deletion...
    on Jun 25, 2019
  23. mapk commented on May 12, 2020

    @mapk
    Contributor

    Has this been resolved? I can click and highlight across multiple blocks, but as soon as I let up from the mouse, the Editor forces the blocks themselves to be selected, not the text. Is this issue still a problem?

    select

  24. mtias commented on May 13, 2020

    @mtias
    Member

    That's the thing we wanted to see if it was worth implementing at some point — partial selections between consecutive blocks so you could merge two paragraphs, etc.

  25. ellatrix commented on Aug 20, 2020

    @ellatrix
    Member

    Let's close this issue. Most of what's described here has been accomplished. We should open follow up issues for additional enhancements like partial block selection and fixing remaining issues.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions