Skip to content

Commit

Permalink
Fixes #82701: Not expected } input when using Chinese input method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Oct 22, 2019
1 parent 3082edc commit 31c7e3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/vs/editor/common/controller/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {

private _isHandling: boolean;
private _isDoingComposition: boolean;
private _selectionsWhenCompositionStarted: Selection[] | null;
private _columnSelectData: IColumnSelectData | null;
private _autoClosedActions: AutoClosedAction[];
private _prevEditOperationType: EditOperationType;
Expand All @@ -188,6 +189,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {

this._isHandling = false;
this._isDoingComposition = false;
this._selectionsWhenCompositionStarted = null;
this._columnSelectData = null;
this._autoClosedActions = [];
this._prevEditOperationType = EditOperationType.Other;
Expand Down Expand Up @@ -667,6 +669,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {

if (handlerId === H.CompositionStart) {
this._isDoingComposition = true;
this._selectionsWhenCompositionStarted = this.getSelections().slice(0);
return;
}

Expand Down Expand Up @@ -757,7 +760,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
if (!this._isDoingComposition && source === 'keyboard') {
// composition finishes, let's check if we need to auto complete if necessary.
const autoClosedCharacters = AutoClosedAction.getAllAutoClosedCharacters(this._autoClosedActions);
this._executeEditOperation(TypeOperations.compositionEndWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), autoClosedCharacters));
this._executeEditOperation(TypeOperations.compositionEndWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this._selectionsWhenCompositionStarted, this.getSelections(), autoClosedCharacters));
this._selectionsWhenCompositionStarted = null;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/vs/editor/common/controller/cursorTypeOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,12 @@ export class TypeOperations {
/**
* This is very similar with typing, but the character is already in the text buffer!
*/
public static compositionEndWithInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], autoClosedCharacters: Range[]): EditOperationResult | null {
public static compositionEndWithInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selectionsWhenCompositionStarted: Selection[] | null, selections: Selection[], autoClosedCharacters: Range[]): EditOperationResult | null {
if (!selectionsWhenCompositionStarted || Selection.selectionsArrEqual(selectionsWhenCompositionStarted, selections)) {
// no content was typed
return null;
}

let ch: string | null = null;
// extract last typed character
for (const selection of selections) {
Expand Down
20 changes: 20 additions & 0 deletions src/vs/editor/test/browser/controller/cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5029,6 +5029,26 @@ suite('autoClosingPairs', () => {
mode.dispose();
});

test('issue #82701: auto close does not execute when IME is canceled via backspace', () => {
let mode = new AutoClosingMode();
usingCursor({
text: [
'{}'
],
languageIdentifier: mode.getLanguageIdentifier()
}, (model, cursor) => {
cursor.setSelections('test', [new Selection(1, 2, 1, 2)]);

// Typing a + backspace
cursorCommand(cursor, H.CompositionStart, null, 'keyboard');
cursorCommand(cursor, H.Type, { text: 'a' }, 'keyboard');
cursorCommand(cursor, H.ReplacePreviousChar, { replaceCharCnt: 1, text: '' }, 'keyboard');
cursorCommand(cursor, H.CompositionEnd, null, 'keyboard');
assert.equal(model.getValue(), '{}');
});
mode.dispose();
});

test('issue #20891: All cursors should do the same thing', () => {
let mode = new AutoClosingMode();
usingCursor({
Expand Down

0 comments on commit 31c7e3b

Please sign in to comment.