-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Handle IME composing state in onBeforeInput
#1107
Conversation
@doodlewind this is an extremely written up PR! Thank you! I'll be back in a few hours and I can check this out locally and hope to get it merged. Thanks for taking the time to work on this! |
@@ -7,7 +7,7 @@ | |||
*/ | |||
|
|||
function findDeepestNode(element) { | |||
return element.firstChild | |||
return element && element.firstChild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@doodlewind do you know where this was causing an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been done with another PR. When element itself is null, IMO returning null is somehow better then throwing an error. This happens when removing nodes in a loose schema. Sorry for not providing reproduction here, while if this is not suitable to be merged here, it's okay to close this with another pull request.😅
@doodlewind thank you for the thorough write-up! I'd looked at the IME problem when I opened #1012 and I understand your solution echoes PR #885, that is go around the problem introduced by the iOS autocomplete fix for composition specifically. I have a feeling that composition may not be the only area affected by that, so merging this patch will potentially obscure other issues. An alternative approach, which IMO is cleaner, will be to drop that iOS autocomplete fix and use Input Events generated by iOS 10.1+ (as per this comment, it's not a tragedy to not support iOS <=10.0) |
@danburzo thanks for your insight! |
Closing this since my forked branch contains some unrelated changes. |
This PR suggests a moderate solution for issue #854 based on PR #885 and #880, which can also be a prerequisite to solve issue #1012.
Desktop IME has native behaviors which is different from mobile. Briefly, there are three types of events related to IME:
onCompositionStart
onCompositionUpdate
onCompositionEnd
On mobile the
onCompositionStart
andonCompositionUpdate
event does not ever fire since user can choose words inside IME UI and insert the result all at once withonCompositionEnd
fires. On desktop the default behavior generally works as below:onCompositionStart
fires.onCompositionUpdate
fires on each key down, but during whichonKeyDown
does not fire.onBeforeInput
fires.onBeforeInput
fires,onCompositionEnd
fires.One essential key to IME related issues is that
onBeforeInput
fires beforeonCompositionEnd
, so it's necessary foronBeforeInput
to know whether current input state is composing. In this PR we mimic the onKeyDown way that pass in aisComposing
state insidedata
arg to plugin'sonBeforeInput
, which enables both core and custom plugins to add extra logic fixing IME state.As as result,
onBeforeInput
inside core plugin can have more control: The reason causes #854 is that during desktop IME inputs, the iOS COMPAT code which manually changes selection inside core plugin'sonBeforeInput
should not have been worked. Here is an example:haode
stroke, IME will interpret the keys ashao'de
with 6 letters, which appears on screen underlined (haode
means好(hao)的(de)
in Chinese).onBeforeInput
fires.好的
applys to state, the iOS COMPAT code insideonBeforeInput
will consider it a mismatch, selecting a new selection with a width of 6 letters after current cursor, then replace them with好的
, but since the temp lettershao'de
is natively removed by browser, this is not necessary, resulting 'eating' letters after current cursor.In this case, with
isComposing
provided to plugin, simply ignoring iOS COMPAT code on desktop solves this issue.Hope it helps :-)