-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Nested contenteditables + comment markers make page jumps #4412
Comments
I think It has nothing to do with comment contenteditable. When clicking the marker inside nested contenteditable then 3 things happen at the same time:
I guess something is happening (selection or focus update) while marker's span update and the target element is not present in the DOM. |
It's just a quick shoot. I haven't debugged it deeply. |
Hi guys... I had similar problem while creating a custom selection for tables (block selection). I set selection in model and I neeed to stop selection rendering then to not make selection flicker. I've added simple switch: // TODO: Add temporary solution to pausing selection rendering.
if ( this.renderSelection ) {
this._updateSelection();
this._updateFocus();
} and I use it to pause selection rendering during block selection. Without pausing something (the DOM?) was interferring with model selection and the whole thing doesn't worked well. |
I think that the guilty line is: https://github.com/ckeditor/ckeditor5-engine/blob/5c0a34d6f277fed063d8ed40af5b8ebda4690e14/src/view/renderer.js#L756 (as you mentioned before). It updates focus on the "selection update" part of the rendering in a very naive way (note that we update focus in the "focus update" part in a much more complex way, including checking When I started logging When I click on the comment in table editor, lose focus for a while and use global contenteditable a the |
Also, I think that @jodator case in not related to this issue. But as long as we will not solve both I will not be sure. |
So, with @Reinmar we were able to debug this problem. The flow is like this:
At this point:
Then this code is executed: https://github.com/ckeditor/ckeditor5-engine/blob/5c0a34d6f277fed063d8ed40af5b8ebda4690e14/src/view/renderer.js#L739-L756 It takes the selection from view, asks for the corresponding DOM element and tries to focus it. However, because the view has an old selection it returns wrong editable element (main one) in which there is no DOM selection (because the selection is already in the nested editable). Focusing element with no selection cases page jump. TADAM! |
I pushed the proposal of the fix to t/1528. If prevent rendering when the user is in the model change block. On the one hand, this is something I was thinking about for a long time. On the other, there is a reason we delayed this change for that long. It is ugly and makes "big look" logic even more complex. |
I'm ok with that change. Maybe not the code itself (that flag should be protected (for now), there's a code style issue and |
Internal: Prevent rendering when in the `model.change()` or `model.enqueueChange()` block. Closes #1528.
…ueChange()` block. Closes #1528.
How to reproduce?
Current behavior:
Scroll jumps to the top.
Additional info
Reproducible on Chrome, Safari
The same happens with table cells.
I've tried to debug it with @oskarwrobel and here are our thoughts:
Clicking the marker makes the comment's contenteditable active and triggers its rendering. Then Clicking outside of it, makes it inactive, rerenders the comment and rerenders the main content editable element. It triggers two times https://github.com/ckeditor/ckeditor5-engine/blob/5c0a34d6f277fed063d8ed40af5b8ebda4690e14/src/view/renderer.js#L756
which probably doesn't find the selection in the editor for the second time, thus it creates a selection for a while at the top of the editor and scrolls to it.
Possible solutions:
setTimeout 0
in comments when they change state between active and inactive.domElement.focus( { preventScroll: false } )
. Unfortunately, it works only in Chrome, doesn't work in Safari and it looks like a "postfixer".WDYT?
cc @pjasiun @Reinmar
The text was updated successfully, but these errors were encountered: