This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
[IME][Safari] Fix IME composistion broken Issue in empty paragraph in Safari #217
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This issue was originally described in ckeditor/ckeditor5#1333.
After some digging, I found the
_updateSelection
call inrender
method unnecessarily update the DOM selection after I start composing in an empty paragraph, which breaks the composition.I continued looking into the
_updateSelection
method. DOM selection is different from view selection when we type the first character, which is why_domSelectionNeedsUpdate
returns true.So why the DOM selection is different from view selection only after we type the first character in an empty paragraph? And only in Safari? I debugged related code with several console logs, and then found out a weird behavior of composition in Safari: the selection won't be collapsed while composing. More precisely, when we type character
c
with Chinese IME in an empty paragraph, the selection would be[c]
, instead ofc[]
. You can have try with my test code in Safari: https://codepen.io/farthinker/pen/KOoNJY?editors=1111.Thanks to this weird behavior in Safari,
_handleTextNodeInsertion
method cannot correctly setresultRange
of input command, and input command only predictresultRange
from the length of inserted text and default it to be collapsed.BTW,
_handleTextMutation
method would predict theresultRange
from the actual DOM selection, so composition won't break in the following typings.I think it's reasonable to always respect the actual DOM selection while composing, no matter in what browser, as any unnecessary selection/DOM update could break the composition. But the problem is when we handle text node insertion we cannot convert actual DOM selection to view selection, because the text node is already in the DOM, but it's not been created in the model yet. All we can do is try our best to guess. My fix solution is also a prediction about the result selection, but in a more precise way.