mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-11 05:30:03 -05:00
Fixes #19291: electric character only works if the text before the closing bracket is whitespace only
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user