Skip to content

Commit 91334c8

Browse files
committed
Fix microsoft#24557. Unconfirmed text of CJK IME collapse to one character due to known bug in Chrome v55 and v56.
1 parent 0656b2b commit 91334c8

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

src/vs/editor/common/controller/textAreaHandler.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export interface ICompositionStartData {
4040
}
4141

4242
// See https://github.com/Microsoft/monaco-editor/issues/320
43-
const isChromev55 = (
44-
navigator.userAgent.indexOf('Chrome/55.') >= 0
43+
const isChromev55_v56 = (
44+
(navigator.userAgent.indexOf('Chrome/55.') >= 0 || navigator.userAgent.indexOf('Chrome/56.') >= 0)
4545
/* Edge likes to impersonate Chrome sometimes */
4646
&& navigator.userAgent.indexOf('Edge/') === -1
4747
);
@@ -118,6 +118,7 @@ export class TextAreaHandler extends Disposable {
118118
this._register(this.textArea.onKeyPress((e) => this._onKeyPressHandler(e)));
119119

120120
this.textareaIsShownAtCursor = false;
121+
let compositionLocale = null;
121122

122123
this._register(this.textArea.onCompositionStart((e) => {
123124

@@ -139,15 +140,16 @@ export class TextAreaHandler extends Disposable {
139140
}));
140141

141142
this._register(this.textArea.onCompositionUpdate((e) => {
142-
if (isChromev55) {
143+
if (isChromev55_v56) {
143144
// See https://github.com/Microsoft/monaco-editor/issues/320
144-
// where compositionupdate .data is broken in Chrome v55
145+
// where compositionupdate .data is broken in Chrome v55 and v56
145146
// See https://bugs.chromium.org/p/chromium/issues/detail?id=677050#c9
146-
e = {
147-
locale: e.locale,
148-
data: this.textArea.getValue()
149-
};
147+
compositionLocale = e.locale;
148+
// The textArea doesn't get the composition update yet, the value of textarea is still obsolete
149+
// so we can't correct e at this moment.
150+
return;
150151
}
152+
151153
this.textAreaState = this.textAreaState.fromText(e.data);
152154
let typeInput = this.textAreaState.updateComposition();
153155
this._onType.fire(typeInput);
@@ -198,6 +200,18 @@ export class TextAreaHandler extends Disposable {
198200
this._register(this.textArea.onInput(() => {
199201
// console.log('onInput: ' + this.textArea.getValue());
200202
if (this.textareaIsShownAtCursor) {
203+
// See https://github.com/Microsoft/monaco-editor/issues/320
204+
if (isChromev55_v56) {
205+
let text = this.textArea.getValue();
206+
this.textAreaState = this.textAreaState.fromText(text);
207+
let typeInput = this.textAreaState.updateComposition();
208+
this._onType.fire(typeInput);
209+
let e = {
210+
locale: compositionLocale,
211+
data: text
212+
};
213+
this._onCompositionUpdate.fire(e);
214+
}
201215
// console.log('::ignoring input event because the textarea is shown at cursor: ' + this.textArea.getValue());
202216
return;
203217
}

0 commit comments

Comments
 (0)