ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Fixed DOM selection rendering after missing selectionchange event

Open niegowski opened this issue 3 years ago • 3 comments

Suggested merge commit message (convention)

Fix (engine): Selection change should not be lost even if some selectionchange events won't get fired. Closes #12219.


Additional information

See https://github.com/ckeditor/ckeditor5/issues/12219#issuecomment-1205225533

niegowski avatar Aug 04 '22 14:08 niegowski

@ckeditor/qa-team could you verify if this fixes the original issue?

niegowski avatar Aug 04 '22 15:08 niegowski

I just briefly scanned the code out of curiosity how complex was the fix, but I didn't actually review this.

One general remark: Please leave traces to this ticket in the code. I'd add them in the condition that uses this flag and in the test added for this scenario.

Reinmar avatar Aug 05 '22 07:08 Reinmar

@niegowski unfortunately, the original issue is not fixed. Actually, with these changes, I can't place the selection anywhere, as it jumps to the beginning of the document.

Mgsy avatar Aug 05 '22 08:08 Mgsy

Interestingly one user from our community reports that this PR fixes also another issue (#12008). Worth to check it once the PR is ready.

mlewand avatar Aug 29 '22 11:08 mlewand

@ckeditor/qa-team could you please retest this PR? Now it upcasts DOM selection just before the selection is completed so the model selection is up to date with the DOM selection before the render is triggered.

niegowski avatar Sep 03 '22 14:09 niegowski

This is weird. Currently I'm not able to reproduce the original scenario on docs (older versions and latest) or locally on master. It works fine everywhere (on this branch too). The only thing that changed since I checked it last time is I upgraded Chrome to Version 105.0.5195.102.

Could someone confirm?

FilipTokarski avatar Sep 06 '22 08:09 FilipTokarski

@FilipTokarski, I was able to achieve such behaviour (which I suppose is the original issue) on online docs (https://ckeditor.com/docs/ckeditor5/latest/examples/builds/classic-editor.html): selection jumps

However, CPU throttling is required for achieving reproduction.

dufipl avatar Sep 06 '22 09:09 dufipl

I know, I tested it with 6x CPU slowdown. What is your Chrome version?

FilipTokarski avatar Sep 06 '22 09:09 FilipTokarski

105.0.5195.52 (arm64)

dufipl avatar Sep 06 '22 09:09 dufipl

I've just upgraded to: 105.0.5195.102 (arm64) and still can reproduce the issue.

dufipl avatar Sep 06 '22 09:09 dufipl

I've checked both latest docs and docs generated on the PR with x6 CPU throttling. The issue still persists on the latest docs (although in much milder form than it used to - as shown on video below), I can't seem to reproduce it on PR at all.

https://user-images.githubusercontent.com/66953380/188818999-d0683b84-7f73-4295-ab35-aa3c8cbf3fe0.mov

@dufipl did you check if the issue persists for you on the PR?

Acrophost avatar Sep 07 '22 07:09 Acrophost

@Acrophost, on this PR the selection does not jump anymore and the editor is usable. However, on my side, some slowness in its work is possible to see.

dufipl avatar Sep 07 '22 11:09 dufipl

This PR is triggering the DOM selection upcast (and flush of DOM mutations) on mouseup DOM event (and keyup/down if isSelecting = true). It's triggered only when there was a selectstart DOM event that did not finish yet. This is introduced to make sure that the model/view selection is matching the DOM selection. The selectionchange DOM event is asynchronous and sometimes is fired too late so we sometimes "corrected" the DOM selection to the last known model selection but that was incorrect because of the asynchronous selectionchange event.

@Reinmar @scofalik do you see any potential problems with this approach?

niegowski avatar Sep 07 '22 12:09 niegowski

I've read the discussion in issue and looked at changes. They seem fine and reasonable to me but honestly -- I am so out-of-touch with this part of the engine that my opinion doesn't really bring any value.

scofalik avatar Sep 08 '22 09:09 scofalik

To me, the change looks good too. It seems safe to upcast the selection at that point.

Reinmar avatar Sep 12 '22 12:09 Reinmar