Added support for the compositionupdate event#1285
Added support for the compositionupdate event#1285mathieumg wants to merge 2 commits intofacebookarchive:mainfrom
compositionupdate event#1285Conversation
|
Thanks for making this into a PR!
Nah, we always 'Squash and merge' when merging, so you can leave the commits separate if that's easier for you. |
I totally forgot GitHub added that as a feature a while ago, all good! 👍 |
flarnie
left a comment
There was a problem hiding this comment.
Thanks again for making this PR @mathieumg!
@spicyj, @paloobi, myself, and other internal folks were discussing this, and here was our thinking:
- we would prefer to default to using 'onBeforeInput' and falling back to 'onCompositionUpdate' rather than defaulting to using 'onCompositionUpdate'. There are inconsistencies in composition events across different browser/OS combinations, in general, and the smallest initial change would be to use 'onCompositionUpdate' as a fallback.
- We'd like to wrap the changed behavior in a feature-flag so that we can test internally. I'm happy to add a commit to this PR doing that, or if you want to here is the way it usually works: https://github.com/facebook/draft-js/wiki/Draft-Feature-Flags
(if that doesn't make sense please ask - I just wrote it, and there could be inconsistencies.) - I'm going to do some browser testing in IE/Edge and with different IME input, and see if there are any issues with this approach.
Let me know if you are too busy and if so I can try to update this.
|
Also, one other thing: onBeforeInput is not actually the browser's native event. We polyfill it in many cases inside of React here: https://github.com/facebook/react/blob/3b5e3b5a23069dd03feaa6979bccb64de4d76d09/src/renderers/dom/shared/eventPlugins/BeforeInputEventPlugin.js. It might make sense to switch that logic so that onBeforeInput events are properly synthesized based on the composition events that Android provides, and then we don't need to change Draft proper at all. |
|
@flarnie Thanks for the return! I just got home right now, will try to update the PR ASAP! |
|
Hi again - Issue #1 Issue #2 I manually tested Korean, and also recorded the input events using https://dvcs.w3.org/hg/d4e/raw-file/tip/key-event-test.html in Chrome on mac. You can see that the data doesn't contain the whole composition, and so it ends up clearing the composition at the end and replacing it with the last character: This is inconsistent with Japanese I think, where the data on the 'onCompositionUpdate' contains the entire composition so far. Japanese seemed to work ok with this fix, but I still would be concerned about subtle changes there. I'm attaching pdfs of the keypress events for Korean and Japanese examples, for reference. Basically I think someone (maybe me eventually) needs to catalogue all the event patterns for different IME and composition use cases, and come up with handlers or modes for the different cases. If you don't need to support Korean or other IME input then this fix may still be good enough for your use case. If you're open to addressing the issues with Korean input I can help look into it, or we can close this pending further investigation. chrome_mac_katana_keyboard_events.pdf |
This continues from facebookarchive#1152 and facebookarchive#1285 making them work together for broad support for polatform inconsistencies.
|
I merged and resolved conflicts with the work done so far by both @njjewers and @mathieumg which hopefully fixes a bunch of issues with IME and Android keyboard weirdness. You can see my result here: master...octatone:raymond/input-bugs I manually tested Korean, Japanese and Chinese (simplified) with these changes, and added unit tests to ensure that further improvements don't break expect normal IME cases. My unit tests are based on captured IME events on Chrome + Windows. Please review and let me know if combining these two bodies of work into one is okay, and I will submit a proper PR with feature flags, etc. |
|
@octatone - this looks interesting, thanks for working on it! I'm working on some React stuff at the moment but will review your result as soon as I can. |
|
@octatone Thanks to you (and everyone else) for your work on this. It's been driving our Android users a bit nutty! I've just tested out your changes with my own Android device and it looks like it clears things up with GBoard but still odd behaviour with SwiftKey - typing any word causes the keyboard to immediately lose focus. But, either way, significantly better than it was. |
sophiebits
left a comment
There was a problem hiding this comment.
(switching away from github review labels; requesting changes to match earlier review above)
|
@tomkelsey Same problem with SwiftKey. If I enter @ or $ before typing it works as intended though. Same for you? |
|
I have opened a PR that continues from this work #1419 |
This continues from facebookarchive#1152 and facebookarchive#1285 making them work together for broad support for polatform inconsistencies.
* Modified compositoin mode event handlers to provide better support for mobile browsers * Added test cases for DraftEditorCompositionHandler * Linter compliance * Added support for `compositionupdate` event. * Made the linter happy! * Normalize beforeInput and compositionUpdate data This continues from facebookarchive#1152 and facebookarchive#1285 making them work together for broad support for polatform inconsistencies. * Put new composition fixes behind a feature flag * lint * correct resets * Fix Synthetic Event flow types * Convert DraftEditorCompositionHandler tests to root tests + snapshots * Remove unnecessary DraftFeatureFlags
…r mobile browsers Added test cases for DraftEditorCompositionHandler Linter compliance Added support for `compositionupdate` event. Made the linter happy! Normalize beforeInput and compositionUpdate data This continues from facebookarchive#1152 and facebookarchive#1285 making them work together for broad support for polatform inconsistencies. Put new composition fixes behind a feature flag lint correct resets Fix Synthetic Event flow types Convert DraftEditorCompositionHandler tests to root tests + snapshots
…r mobile browsers Added test cases for DraftEditorCompositionHandler Linter compliance Added support for `compositionupdate` event. Made the linter happy! Normalize beforeInput and compositionUpdate data This continues from facebookarchive#1152 and facebookarchive#1285 making them work together for broad support for polatform inconsistencies. Put new composition fixes behind a feature flag lint correct resets Fix Synthetic Event flow types Convert DraftEditorCompositionHandler tests to root tests + snapshots
…r mobile browsers Added test cases for DraftEditorCompositionHandler Linter compliance Added support for `compositionupdate` event. Made the linter happy! Normalize beforeInput and compositionUpdate data This continues from facebookarchive#1152 and facebookarchive#1285 making them work together for broad support for polatform inconsistencies. Put new composition fixes behind a feature flag lint correct resets Fix Synthetic Event flow types Convert DraftEditorCompositionHandler tests to root tests + snapshots

Summary
@flarnie As we discussed, this adds support for the
compositionupdateevent and ignores thebeforeinputevent if it were to be fired in that scenario too. I imagine a slightly cleaner way of doing this would be to remove the listener onbeforeinputaltogether when we realizecompositionupdatefires. Should I squash my changes?Test Plan
I didn't add new tests, should I add tests that fail without this fix?