mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Use fallback data for composition events if necessary
This commit is contained in:
1 parent
c6f91ee6e8
commit
ad70848e80
1 file changed
+30
-6
@@ -31,8 +31,22 @@ var keyOf = require('keyOf');
|
||||
var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
|
||||
var START_KEYCODE = 229;
|
||||
|
||||
var useCompositionEvent = ExecutionEnvironment.canUseDOM &&
|
||||
'CompositionEvent' in window;
|
||||
var useCompositionEvent = (
|
||||
ExecutionEnvironment.canUseDOM &&
|
||||
'CompositionEvent' in window
|
||||
);
|
||||
|
||||
// In IE9+, we have access to composition events, but the data supplied
|
||||
// by the native compositionend event may be incorrect. In Korean, for example,
|
||||
// the compositionend event contains only one character regardless of
|
||||
// how many characters have been composed since compositionstart.
|
||||
// We therefore use the fallback data while still using the native
|
||||
// events as triggers.
|
||||
var useFallbackData = (
|
||||
!useCompositionEvent ||
|
||||
'documentMode' in document && document.documentMode > 8
|
||||
);
|
||||
|
||||
var topLevelTypes = EventConstants.topLevelTypes;
|
||||
var currentComposition = null;
|
||||
|
||||
@@ -207,13 +221,23 @@ var CompositionEventPlugin = {
|
||||
eventType = getCompositionEventType(topLevelType);
|
||||
} else if (!currentComposition) {
|
||||
if (isFallbackStart(topLevelType, nativeEvent)) {
|
||||
eventType = eventTypes.start;
|
||||
currentComposition = new FallbackCompositionState(topLevelTarget);
|
||||
eventType = eventTypes.compositionStart;
|
||||
}
|
||||
} else if (isFallbackEnd(topLevelType, nativeEvent)) {
|
||||
eventType = eventTypes.compositionEnd;
|
||||
data = currentComposition.getData();
|
||||
currentComposition = null;
|
||||
}
|
||||
|
||||
if (useFallbackData) {
|
||||
// The current composition is stored statically and must not be
|
||||
// overwritten while composition continues.
|
||||
if (!currentComposition && eventType === eventTypes.compositionStart) {
|
||||
currentComposition = new FallbackCompositionState(topLevelTarget);
|
||||
} else if (eventType === eventTypes.compositionEnd) {
|
||||
if (currentComposition) {
|
||||
data = currentComposition.getData();
|
||||
currentComposition = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType) {
|
||||
|
||||
Reference in new issue
Block a user