diff --git a/src/vs/editor/common/controller/cursorTypeOperations.ts b/src/vs/editor/common/controller/cursorTypeOperations.ts index 1cab5adaa4f36169e7dfb94cb4d1fa41bab7e900..72546cb0c00d8ff6d4808131b11fb2d2e0b8a2df 100644 --- a/src/vs/editor/common/controller/cursorTypeOperations.ts +++ b/src/vs/editor/common/controller/cursorTypeOperations.ts @@ -19,7 +19,6 @@ import { SurroundSelectionCommand } from 'vs/editor/common/commands/surroundSele import { IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter'; import { getMapForWordSeparators, WordCharacterClass } from 'vs/editor/common/controller/wordCharacterClassifier'; import { CharCode } from 'vs/base/common/charCode'; -import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair'; export class TypeOperations { diff --git a/src/vs/editor/test/browser/controller/cursor.test.ts b/src/vs/editor/test/browser/controller/cursor.test.ts index be832003143502cb5ad5465d41fd0814caae52b9..ead2a6e5b21c9403b653202c94a3a95cc6bc6a21 100644 --- a/src/vs/editor/test/browser/controller/cursor.test.ts +++ b/src/vs/editor/test/browser/controller/cursor.test.ts @@ -3947,6 +3947,21 @@ suite('autoClosingPairs', () => { ], })); } + + public setAutocloseEnabledSet(chars: string) { + this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), { + autoCloseBefore: chars, + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '\'', close: '\'', notIn: ['string', 'comment'] }, + { open: '\"', close: '\"', notIn: ['string'] }, + { open: '`', close: '`', notIn: ['string', 'comment'] }, + { open: '/**', close: ' */', notIn: ['string'] } + ], + })); + } } const enum ColumnType { @@ -4028,6 +4043,7 @@ suite('autoClosingPairs', () => { test('configurable open parens', () => { let mode = new AutoClosingMode(); + mode.setAutocloseEnabledSet('abc'); usingCursor({ text: [ 'var a = [];', @@ -4041,11 +4057,7 @@ suite('autoClosingPairs', () => { ], languageIdentifier: mode.getLanguageIdentifier(), editorOpts: { - autoClosingBrackets: { - enabledBefore: 'abc', - autoClose: true, - autoWrap: true - } + autoClosingBrackets: 'languageDefined' } }, (model, cursor) => { @@ -4091,16 +4103,8 @@ suite('autoClosingPairs', () => { ], languageIdentifier: mode.getLanguageIdentifier(), editorOpts: { - autoClosingBrackets: { - enabledBefore: 'abc', - autoClose: false, - autoWrap: true - }, - autoClosingQuotes: { - enabledBefore: 'abc', - autoClose: false, - autoWrap: true - } + autoClosingBrackets: 'never', + autoClosingQuotes: 'never' } }, (model, cursor) => { @@ -4152,17 +4156,14 @@ suite('autoClosingPairs', () => { assert.equal(model.getValue(), '`var` a = `asd`'); }); + usingCursor({ text: [ 'var a = asd' ], languageIdentifier: mode.getLanguageIdentifier(), editorOpts: { - autoClosingQuotes: { - autoWrap: false, - autoClose: true, - enabledBefore: '' - } + autoWrapping: 'never' } }, (model, cursor) => { @@ -4175,6 +4176,46 @@ suite('autoClosingPairs', () => { assert.equal(model.getValue(), '` a = asd'); }); + + usingCursor({ + text: [ + 'var a = asd' + ], + languageIdentifier: mode.getLanguageIdentifier(), + editorOpts: { + autoWrapping: 'quotes' + } + }, (model, cursor) => { + + cursor.setSelections('test', [ + new Selection(1, 1, 1, 4), + ]); + + // type a ` + cursorCommand(cursor, H.Type, { text: '`' }, 'keyboard'); + + assert.equal(model.getValue(), '`var` a = asd'); + }); + + usingCursor({ + text: [ + 'var a = asd' + ], + languageIdentifier: mode.getLanguageIdentifier(), + editorOpts: { + autoWrapping: 'brackets' + } + }, (model, cursor) => { + + cursor.setSelections('test', [ + new Selection(1, 1, 1, 4), + ]); + + // type a ` + cursorCommand(cursor, H.Type, { text: '(' }, 'keyboard'); + + assert.equal(model.getValue(), '(var) a = asd'); + }); mode.dispose(); });