Fixes #19291: electric character only works if the text before the closing bracket is whitespace only

This commit is contained in:
Alex Dima
2017-01-25 14:53:56 +01:00
parent 021c1f5a40
commit b1c8dad73e
2 changed files with 24 additions and 1 deletions

View File

@@ -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
};

View File

@@ -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({