提交 4e3383f1 编写于 作者: P Peng Lyu

Fix microsoft/monaco-editor#545. Composition data is wrong when typing numbers in Chinese.

上级 2b941e42
...@@ -164,6 +164,26 @@ export class TextAreaInput extends Disposable { ...@@ -164,6 +164,26 @@ export class TextAreaInput extends Disposable {
return [newState, typeInput]; return [newState, typeInput];
}; };
const compositionDataInValid = (locale: string): boolean => {
// https://github.com/Microsoft/monaco-editor/issues/339
// Multi-part Japanese compositions reset cursor in Edge/IE, Chinese and Korean IME don't have this issue.
// The reason that we can't use this path for all CJK IME is IE and Edge behave differently when handling Korean IME,
// which breaks this path of code.
if (browser.isEdgeOrIE && locale === 'ja') {
return true;
}
// https://github.com/Microsoft/monaco-editor/issues/545
// On IE11, we can't trust composition data when typing Chinese as IE11 doesn't emit correct
// events when users type numbers in IME.
// Chinese: zh-Hans-CN, zh-Hans-SG, zh-Hant-TW, zh-Hant-HK
if (browser.isIE && locale.indexOf('zh-Han') === 0) {
return true;
}
return false;
};
this._register(dom.addDisposableListener(textArea.domNode, 'compositionupdate', (e: CompositionEvent) => { this._register(dom.addDisposableListener(textArea.domNode, 'compositionupdate', (e: CompositionEvent) => {
if (browser.isChromev56) { if (browser.isChromev56) {
// See https://github.com/Microsoft/monaco-editor/issues/320 // See https://github.com/Microsoft/monaco-editor/issues/320
...@@ -174,11 +194,7 @@ export class TextAreaInput extends Disposable { ...@@ -174,11 +194,7 @@ export class TextAreaInput extends Disposable {
return; return;
} }
if (browser.isEdgeOrIE && e.locale === 'ja') { if (compositionDataInValid(e.locale)) {
// https://github.com/Microsoft/monaco-editor/issues/339
// Multi-part Japanese compositions reset cursor in Edge/IE, Chinese and Korean IME don't have this issue.
// The reason that we can't use this path for all CJK IME is IE and Edge behave differently when handling Korean IME,
// which breaks this path of code.
const [newState, typeInput] = deduceInputFromTextAreaValue(/*couldBeEmojiInput*/false); const [newState, typeInput] = deduceInputFromTextAreaValue(/*couldBeEmojiInput*/false);
this._textAreaState = newState; this._textAreaState = newState;
this._onType.fire(typeInput); this._onType.fire(typeInput);
...@@ -193,13 +209,12 @@ export class TextAreaInput extends Disposable { ...@@ -193,13 +209,12 @@ export class TextAreaInput extends Disposable {
})); }));
this._register(dom.addDisposableListener(textArea.domNode, 'compositionend', (e: CompositionEvent) => { this._register(dom.addDisposableListener(textArea.domNode, 'compositionend', (e: CompositionEvent) => {
if (browser.isEdgeOrIE && e.locale === 'ja') { if (compositionDataInValid(e.locale)) {
// https://github.com/Microsoft/monaco-editor/issues/339 // https://github.com/Microsoft/monaco-editor/issues/339
const [newState, typeInput] = deduceInputFromTextAreaValue(/*couldBeEmojiInput*/false); const [newState, typeInput] = deduceInputFromTextAreaValue(/*couldBeEmojiInput*/false);
this._textAreaState = newState; this._textAreaState = newState;
this._onType.fire(typeInput); this._onType.fire(typeInput);
} } else {
else {
const [newState, typeInput] = deduceComposition(e.data); const [newState, typeInput] = deduceComposition(e.data);
this._textAreaState = newState; this._textAreaState = newState;
this._onType.fire(typeInput); this._onType.fire(typeInput);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册