ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Introduce a way to reach unaccessible places (aka magicline and magicblock) - stage I

Open Reinmar opened this issue 9 years ago • 69 comments

Problem:

image

In CKEditor 4 this problem was solved by the magicline plugin. We need some solution for CKEditor 5 as well.

The discussion started in relation to autoparagraphing. Interesting comments:

  • https://github.com/ckeditor/ckeditor5/issues/331#issuecomment-247336739
  • https://github.com/ckeditor/ckeditor5/issues/331#issuecomment-281646290
  • https://github.com/ckeditor/ckeditor5/issues/331#issuecomment-281648038
  • https://github.com/ckeditor/ckeditor5/issues/331#issuecomment-281649188
  • https://github.com/ckeditor/ckeditor5/issues/331#issuecomment-281654155
  • https://github.com/ckeditor/ckeditor5/issues/331#issuecomment-281657728

If you would like this feature to be implemented ASAP, please react with 👍 to this post.

Reinmar avatar Feb 22 '17 12:02 Reinmar

DUP reported in https://github.com/ckeditor/ckeditor5/issues/685.

Reinmar avatar Nov 22 '17 14:11 Reinmar

I promised to describe here some simpler workarounds for this problem. They are much easier to implement than Magicline and perhaps might even be a good start for us.

Additionally, I noticed two things when describing these solutions:

  • that with a bit more work those solutions would also solve the problem of broken Ctrl+A when widget is the first/last element of the content,
  • and that they don't conflict with a magicline-like solution that much (so they can be treated as addition to magicline, not a replacement).

Solution 1

  1. Listen to selection changes.
  2. Once discovering that an object type of element is selected (e.g. an image), insert a paragraph before/after it if it's at the very start/end of the content. Such insertion should happen in a transparent batch to not create an undo step.
  3. Remove these paragraphs if they are still empty after the selection is moved somewhere else.

Pros:

  • Quite simple to implement.
  • Well discoverable for the users.
  • Similar to how image captions work.

Cons:

  • There will be even more blinking (right now only captions appear when you click an image).
  • It would require additional work to filter these paragraphs out in getData() if it was called while an image was selected.
  • You need to know that you have to select the widget first to show these paragraphs.

Solution 2

Like in solution 1 but add these paragraphs only when someone:

  1. selects an image,
  2. presses an arrow key (e.g. down/right if the image is the last element of the content).

Pros:

  • Less intrusive than blinking paragraphs.
  • Quite simple to implement too.

Cons:

  • Less discoverable than Solution 1.

Reinmar avatar Jan 08 '18 10:01 Reinmar

DUP reported in https://github.com/ckeditor/ckeditor5/issues/935.

Reinmar avatar Apr 04 '18 15:04 Reinmar

DUP reported in https://github.com/ckeditor/ckeditor5-engine/issues/1400.

Reinmar avatar Apr 08 '18 17:04 Reinmar

What's the good solution? 🔢

devgogo avatar Apr 09 '18 01:04 devgogo

@Reinmar Don't you think this should be categorized as a bug rather than an enhancement?

Most people type and then insert image at the end of the editor and as a result, cannot continue writing afterward.

Also, I think when a user clicks on image caption and hit enter, it should result in a new paragraph. Maybe, this can be a quick fix for images while the best solution is being decided on.

syavash avatar May 04 '18 09:05 syavash

You may be right. For me, it's a missing feature because I know that it's how browsers work and we need to implement a feature which will allow reaching those places. For the users, this is purely a bug.

Still, it won't change much on how this ticket will be treated. We'd like to close it ASAP because we know that it makes for a bad UX, but we also know the scope of the problem (which is big).

Reinmar avatar May 04 '18 09:05 Reinmar

BTW, @oleq, you can start processing this issue in the back of your head ;)

Reinmar avatar May 04 '18 09:05 Reinmar

cc @dkonopka too

Reinmar avatar May 04 '18 09:05 Reinmar

@Reinmar I totally understand the scope and complications of this problem.

That's why I suggested that maybe initially we can just add a new paragraph when a user clicks on image's caption and hit enter. This won't be a solution when image caption is disabled, but I believe in any case that should be the behavior for captions. (Maybe, I'm wrong).

Thanks for the amazing job you guys are doing with ckeditor5.

syavash avatar May 04 '18 10:05 syavash

That's a good question. In CKEditor 4 Enter opens widget dialogs (e.g. image properties). In CKEditor 5 we don't use dialogs and we used Tab for navigation so far. This leaves Enter unused.

My only worry with using only a keystroke is its discoverability. Still, it might be a good (and quick) start.

Reinmar avatar May 04 '18 10:05 Reinmar

is there any estimate for this issue?

balgev avatar May 14 '18 11:05 balgev

We're about to merge a change which is going to allow inserting paragraphs before/after widgets by using Enter (to insert a paragraph after a widget) and Shift+Enter (to insert a paragraph before a widget). It works like this:

jun-14-2018 15-49-44

It doesn't solve this issue completely. It's sort of a workaround until we'll be able to introduce something with better discoverability (something that reacts to the mouse – like CKEditor 4's magicline).

Still, we'd like to hear your feedback.

PS. This change is going to be released around the next week.

Reinmar avatar Jun 14 '18 13:06 Reinmar

I think having a temporary fix is great, as this issue breaks the editor for users.

My concern would be that in other editors, pressing enter whilst selecting an image often deletes the image, as the intention is to replace it with a new line. (Albeit, most commonly when the image is inline, which isn't the case with ckeditor5)

Instead of waiting for magicline, gapcursor, etc., I think it would be worth mapping the suggested approach above to directional keys too, as mentioned in https://github.com/ckeditor/ckeditor5/issues/407#issuecomment-355927497

mjadobson avatar Jun 15 '18 14:06 mjadobson

My concern would be that in other editors, pressing enter whilst selecting an image often deletes the image

I'm worried about this too. Although, I've realised recently when working on shift+enter that pressing enter on non-collapsed selections might be very uncommon. And that the expected result (inserting a line break) is quite surprising (at least for me) when experienced live.

Anyway, you may be right that with block images we're safer here. If we'd introduce the same for inline images it would be worse.

Instead of waiting for magicline, gapcursor, etc., I think it would be worth mapping the suggested approach above to directional keys too, as mentioned in #407 (comment)

I'm worried that the users would not know that they need to remove these paragraphs that they created this way (if they don't want to type in them). It's not typical for arrow keys to insert new elements.

Therefore, we considered this option but with an additional mechanism which would delete these paragraphs once you'd leave them without typing anything. Plus, which makes all this more complex, these paragraphs should not appear in the model (should be view-layer-only) to not cause some messy behaviours during real-time collaboration and when autosaving the content.

Reinmar avatar Jun 15 '18 15:06 Reinmar

One of the options for the magic-paragraphs is what @fredck proposed some time ago – that they are always present in the view at the beginning/end of the content if starts/ends with a block widget, regardless of where you currently have the selection. They may have a minimal height (even 0px) to not be visible when the selection is somewhere else. Thanks to that:

  • The selection will be automatically (natively) placed there if you click after a widget. At this point we can remove the height:0px style to show this paragraph.
  • Arrow keys will work the same way as clicking – once the selection is placed in one of these paragraphs, we show it.
  • Ctrl+A would always work too because there would always be normal paragraphs at both ends of the content.

Still, the question is whether they should be present in the model. If we'll decide that yes, then getting rid of them in getData() will not be hard. If not, we still have the problem how to render them in the view without polluting the model with them.

Reinmar avatar Jun 15 '18 15:06 Reinmar

I'm worried that the users would not know that they need to remove these paragraphs that they created this way (if they don't want to type in them). It's not typical for arrow keys to insert new elements.

Yeah, it's not ideal. I was thinking along the lines of removing them if they were still empty when the caret moves away. But thinking about it again, deleting is very well understood; I suspect users would remove any unintentional paragraphs without much fuss.

I think the bigger issue, as with the enter key is discoverability.

One of the options for the magic-paragraphs is what @fredck proposed some time ago ...

That approach would certainly solve a lot more of these kinds of quirks.

As it's a temporary workaround, I think having these "magic paragraphs" in the model and filtering them out when calling getData() (or similar), would be a pretty reasonable compromise. However, I don't know the implications of this on collaborative editing.

mjadobson avatar Jun 15 '18 16:06 mjadobson

Since this problem is a bug from user's perspective any way that quickly can help user accessing those areas would be great and I think what @Reinmar proposed would definitely work for now.

Also, when user selects the caption input, I think hitting enter there should result in a new paragraph.

syavash avatar Jun 17 '18 12:06 syavash

Also, when user selects the caption input, I think hitting enter there should result in a new paragraph.

This is unrelated to this ticket. If you'd like to discuss this topic, please report a separate ticket.

Reinmar avatar Jun 17 '18 13:06 Reinmar

that they are always present in the view at the beginning/end of the content

Never talked about the "beginning", but it is an interesting case as well. It may have a more complex UX because while it is ok to have some empty space at the end of the content, it is a no go to have it at the beginning of it. Anyway, it's curious to give it a try.

In any case, I would break this into separate steps... first solving the problem at the end of the document, which may be simpler, then thinking about the beginning of it.

As for the "view vs model" thing, it would be "technically wrong" to have it in the model, as it is not aware of the UX quirks and it should ideally land in the view. Ofc, this will all depend on how easily it can be implemented and, if we face limitations, whichever solution is ok, as long as the problem is solved.

fredck avatar Jun 18 '18 08:06 fredck