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

Selection#getSelectedBlocks() should not return the last block if its content is not selected #4091

Closed
Reinmar opened this issue Jun 27, 2017 · 0 comments · Fixed by ckeditor/ckeditor5-engine#985
Assignees
Labels
package:engine type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Jun 27, 2017

There's a very popular use case in which the selection ends in a block which the user didn't want to select. What's more, the user doesn't see that that additional block was selected too. This results in a confusion when the user tries to change the format (e.g. apply a heading or a list) of the selected blocks.

Example:

<paragrap>Foo</paragraph>
<paragrap>Bar</paragraph>
<paragrap>Baz</paragraph>

If the user triple clicks on the second paragraph the browser will render this (something which looks like just the "Bar" paragraph selected):

jun-26-2017 22-57-50

However, changing the format, will also change the format of the following "Baz" block:

jun-26-2017 22-58-14

The reason why heading is applied to two blocks now is that the selection which browser creates on tripleclick looks like this:

<paragrap>Foo</paragraph>
<paragrap>[Bar</paragraph>
<paragrap>]Baz</paragraph>

So it ends in the 3rd paragraph. In Chrome and Firefox this is pretty much indistinguishable from a selection which would span only over "Bar": <paragraph>[Bar]</paragraph>. Safari is smarter here and renders such a selection:

image

Still, the user is not expecting that the style will affect also the last line as it doesn't seem to be selected at all in neither browser.

What's more – such a selection can not only be created by tripleclicks, but also Shift+arrow (usually, a non-confusing case) or mouse (a confusing case too).

Solution

We can't try to fix the selection (e.g. trim it) in any way as such selections are totally valid and the user must be able to create them (e.g. when changing the selection using Shift+arrow). This means that we can't convert the selection differently from the view to the model or in any way change its model representation. It's just as it is.

The only thing we can do is to not return the last block from "format" oriented methods like Selection#getSelectedBlocks().

This is what Google Docs, despite its completely custom rendering mechanism, do as well as I explained in this comment so we should be really fine.

@Reinmar Reinmar self-assigned this Jun 27, 2017
szymonkups referenced this issue in ckeditor/ckeditor5-engine Jun 28, 2017
Other: The `Selection#getSelectedBlocks()` method will not return a block in which selection ends if no content of that block is selected. Closes #984.

For example, in the following case only the first two paragraphs will be returned:

```html
<paragraph>[Foo</paragraph>
<paragraph>Bar</paragraph>
<paragraph>]Baz</paragraph>
```

The reasoning behind this change is that the user doesn't consider the last block as selected in such a case (as its selection isn't even visible).
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 11 milestone Oct 9, 2019
@mlewand mlewand added status:confirmed type:improvement This issue reports a possible enhancement of an existing feature. package:engine labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:engine type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
2 participants