ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.59k stars 3.7k forks source link

Research blocking rendering selection while selection is being made #10430

Closed Reinmar closed 3 years ago

Reinmar commented 3 years ago

Provide a description of the task

Research needed to move forward #10230.

Scope: Researching this point:

Make sure we don't touch the selection while the selection is in progress

Source: https://github.com/ckeditor/ckeditor5/issues/10230#issuecomment-904686994

Reinmar commented 3 years ago
oleq commented 3 years ago

There are two separate problems that contribute to the glitches with mouse selection anchoring at links/markers/mentions:

DOM selection on the wrong side of the inline filler

We never want to have the DOM selection start before the inline filler (not sure why, though). But this sometimes happens randomly as the user starts selection at a different point (geometrically, using the mouse).

And we fix this if it happens. And as we fix it, we break the flow of the user selection https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/domconverter.js#L1013-L1016

// What user did by accident 
// (also, imagine they are moving mouse right to select more)
<p>[]&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;<a>FOO</a></p>

// We fix into by imperatively collapsing it in DOM.
<p>&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;[]<a>FOO</a></p>

// Which breaks the flow of creating the selection using mouse;
// the selection remains collapsed forever despite moving mouse right.
// BTW: The filler will be also removed (see the second problem) in this case so 
// this HTML is just to give you the idea of what happened.
<p>&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;<a>FO[]O</a></p>

This could be fixed by blocking the imperative rendering of the DOM selection while the selection is being made (which is the scope of the research).

The disappearing inline filler

While the selection is being made, the inline filler disappears because it's no longer needed. When it disappears, the DOM selection anchored in that filler is collapsed by the web browser to the focus position. Then, as the user continues moving the cursor using the mouse, it stays collapsed forever.

// That's cool. We need this filler.
<p>&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;[]<a>FOO</a></p>

// But now the inline filler is obsolete...
<p>&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;&NBR;[<a>F]OO</a></p>

// So the filler is out and the browser DOM selection collapses to the focus position.
// The flow of extending the selection using the mouse was broken.
<p><a>F[]OO</a></p>

This could be fixed by keeping the inline filler as long as the selection stays in the same block.

oleq commented 3 years ago

The research will be followed by a fix in #10562. 

The permanent inline fillers part of the research was moved to #10563.