diff --git a/src/vs/editor/common/controller/cursorTypeOperations.ts b/src/vs/editor/common/controller/cursorTypeOperations.ts index d50d128f0d5..13b79a281fe 100644 --- a/src/vs/editor/common/controller/cursorTypeOperations.ts +++ b/src/vs/editor/common/controller/cursorTypeOperations.ts @@ -464,7 +464,7 @@ export class TypeOperations { } private static _typeInterceptorElectricChar(config: CursorConfiguration, model: ITokenizedModel, cursor: SingleCursorState, ch: string): EditOperationResult { - if (!config.electricChars.hasOwnProperty(ch)) { + if (!config.electricChars.hasOwnProperty(ch) || !cursor.selection.isEmpty()) { return null; } diff --git a/src/vs/editor/test/common/controller/cursor.test.ts b/src/vs/editor/test/common/controller/cursor.test.ts index 315b67ef74a..59ea9aa805c 100644 --- a/src/vs/editor/test/common/controller/cursor.test.ts +++ b/src/vs/editor/test/common/controller/cursor.test.ts @@ -2965,6 +2965,23 @@ suite('ElectricCharacter', () => { }); mode.dispose(); }); + + test('issue #23711: Replacing selected text with )]} fails to delete old text with backwards-dragged selection', () => { + let mode = new ElectricCharMode(); + usingCursor({ + text: [ + '{', + 'word' + ], + languageIdentifier: mode.getLanguageIdentifier() + }, (model, cursor) => { + moveTo(cursor, 2, 5); + moveTo(cursor, 2, 1, true); + cursorCommand(cursor, H.Type, { text: '}' }, 'keyboard'); + assert.deepEqual(model.getLineContent(2), '}'); + }); + mode.dispose(); + }); }); suite('autoClosingPairs', () => {