Repository navigation
Description
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
ephox-mogran commentedon Nov 24, 2017
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.
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
keypressinstead ofkeydown(due to how shift changes them). You'll probably need to use the Range APIs and calldeleteContentsorinsertNodeetc, 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.
anna-harrison commentedon Nov 24, 2017
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
atimmer commentedon Nov 24, 2017
@ephox-mogran Thank you for the comprehensive overview. It’s good to have all this context in one place.
jasmussen commentedon Nov 24, 2017
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.
JJJ commentedon Dec 20, 2017
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:
I see 2 highlights:
I have 2 flow problems:
I have 2 confidence problems:
I think we could improve this with some clever
user-selectCSS 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.karmatosed commentedon Jan 3, 2018
@rosswintle has this to say in #4222:
aduth commentedon Jan 10, 2018
Related: #179
aduth commentedon Jan 10, 2018
Related: #3696
jeffpaul commentedon Jan 26, 2018
This ticket was mentioned in Slack in #core-editor by jeffpaul. View the logs.
mcsf commentedon Jul 16, 2018
As I close #179, I'm attaching this comment here in case the linked demo proves useful:
#179 (comment)
getsource commentedon Oct 11, 2018
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?
6 remaining items
JJJ commentedon Oct 15, 2018
...and...
...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.
getsource commentedon Oct 17, 2018
@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.
chrisvanpatten commentedon Oct 17, 2018
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.
getsource commentedon Oct 17, 2018
Ooo. I like that idea @chrisvanpatten. Especially if it looks like user needs will conflict.
designsimply commentedon Dec 20, 2018
Closed #13026 as a duplicate and wanted to include the video and a note from that report.
mapk commentedon May 12, 2020
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?
mtias commentedon May 13, 2020
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.
ellatrix commentedon Aug 20, 2020
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.