diff --git a/src/vs/editor/common/modes/supports/electricCharacter.ts b/src/vs/editor/common/modes/supports/electricCharacter.ts index f535112a13e..6af3dc36cc3 100644 --- a/src/vs/editor/common/modes/supports/electricCharacter.ts +++ b/src/vs/editor/common/modes/supports/electricCharacter.ts @@ -94,6 +94,12 @@ export class BracketElectricCharacterSupport { return null; } + let textBeforeBracket = text.substring(0, r.startColumn - 1); + if (!/^\s*$/.test(textBeforeBracket)) { + // There is other text on the line before the bracket + return null; + } + return { matchOpenBracket: bracketText }; diff --git a/src/vs/editor/test/common/controller/cursor.test.ts b/src/vs/editor/test/common/controller/cursor.test.ts index 93f65c9e969..1e67fec695f 100644 --- a/src/vs/editor/test/common/controller/cursor.test.ts +++ b/src/vs/editor/test/common/controller/cursor.test.ts @@ -3269,7 +3269,7 @@ suite('ElectricCharacter', () => { }, (model, cursor) => { moveTo(cursor, 2, 2); cursorCommand(cursor, H.Type, { text: '}' }, 'keyboard'); - assert.deepEqual(model.getLineContent(2), ' a}'); + assert.deepEqual(model.getLineContent(2), 'a}'); }); mode.dispose(); }); @@ -3311,6 +3311,23 @@ suite('ElectricCharacter', () => { mode.dispose(); }); + test('is no-op if the line has other content', () => { + let mode = new ElectricCharMode(); + usingCursor({ + text: [ + 'Math.max(', + '\t2', + '\t3' + ], + languageIdentifier: mode.getLanguageIdentifier() + }, (model, cursor) => { + moveTo(cursor, 3, 3); + cursorCommand(cursor, H.Type, { text: ')' }, 'keyboard'); + assert.deepEqual(model.getLineContent(3), '\t3)'); + }); + mode.dispose(); + }); + test('appends text', () => { let mode = new ElectricCharMode(); usingCursor({