Fixes #138095: Do not touch the textarea during a compositionstart event

This commit is contained in:
Alex Dima 2021-11-29 22:55:38 +01:00
parent 9fc5b78314
commit 31fff5074d
No known key found for this signature in database
GPG key ID: 39563C1504FDD0C9
3 changed files with 20 additions and 1 deletions

View file

@ -293,6 +293,11 @@ export class TextAreaHandler extends ViewPart {
visibleRange.left,
canUseZeroSizeTextarea ? 0 : 1
);
// The textarea might contain more than just the currently composed text
// so we will scroll the textarea as much as possible to the left, which
// means that the browser will perfectly center the currently composed text
// when it scrolls to the right to reveal the textarea cursor.
this.textArea.domNode.scrollLeft = 0;
this._render();
}
@ -309,6 +314,11 @@ export class TextAreaHandler extends ViewPart {
}
// adjust width by its size
this._visibleTextArea = this._visibleTextArea.setWidth(measureText(e.data, this._fontInfo));
// The textarea might contain more than just the currently composed text
// so we will scroll the textarea as much as possible to the left, which
// means that the browser will perfectly center the currently composed text
// when it scrolls to the right to reveal the textarea cursor.
this.textArea.domNode.scrollLeft = 0;
this._render();
}));

View file

@ -289,7 +289,6 @@ export class TextAreaInput extends Disposable {
return;
}
this._setAndWriteTextAreaState('compositionstart', TextAreaState.EMPTY);
this._onCompositionStart.fire({ revealDeltaColumns: 0 });
}));

View file

@ -86,6 +86,7 @@ suite('TextAreaInput', () => {
readonly onSyntheticTap = Event.None;
private _state: IRecordedTextareaState;
private _currDispatchingEvent: IRecordedEvent | null;
constructor() {
super();
@ -95,6 +96,7 @@ suite('TextAreaInput', () => {
selectionStart: 0,
value: ''
};
this._currDispatchingEvent = null;
}
public _initialize(state: IRecordedTextareaState): void {
@ -104,6 +106,7 @@ suite('TextAreaInput', () => {
}
public _dispatchRecordedEvent(event: IRecordedEvent): void {
this._currDispatchingEvent = event;
this._state.value = event.state.value;
this._state.selectionStart = event.state.selectionStart;
this._state.selectionEnd = event.state.selectionEnd;
@ -161,12 +164,16 @@ suite('TextAreaInput', () => {
} else {
throw new Error(`Not Implemented`);
}
this._currDispatchingEvent = null;
}
getValue(): string {
return this._state.value;
}
setValue(reason: string, value: string): void {
if (this._currDispatchingEvent?.type === 'compositionstart') {
assert.fail('should not change the state of the textarea in a compositionstart');
}
this._state.value = value;
}
getSelectionStart(): number {
@ -176,6 +183,9 @@ suite('TextAreaInput', () => {
return this._state.selectionDirection === 'backward' ? this._state.selectionStart : this._state.selectionEnd;
}
setSelectionRange(reason: string, selectionStart: number, selectionEnd: number): void {
if (this._currDispatchingEvent?.type === 'compositionstart') {
assert.fail('should not change the state of the textarea in a compositionstart');
}
this._state.selectionStart = selectionStart;
this._state.selectionEnd = selectionEnd;
this._state.selectionDirection = (selectionStart !== selectionEnd ? 'forward' : 'none');