未验证 提交 881258d0 编写于 作者: P Peng Lyu 提交者: GitHub

Merge pull request #55315 from MattHardcastle/fix-auto-close

Do not auto-close when ending with open
......@@ -121,7 +121,8 @@ export class BracketElectricCharacterSupport {
}
// check if the full open bracket matches
let actual = line.substring(line.length - pair.open.length + 1) + character;
let start = column - pair.open.length + 1;
let actual = line.substring(start - 1, column - 1) + character;
if (actual !== pair.open) {
continue;
}
......
......@@ -4384,6 +4384,51 @@ suite('autoClosingPairs', () => {
mode.dispose();
});
test('issue #55314: Do not auto-close when ending with open', () => {
const languageId = new LanguageIdentifier('myElectricMode', 5);
class ElectricMode extends MockMode {
constructor() {
super(languageId);
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '\"', close: '\"', notIn: ['string'] },
{ open: 'B\"', close: '\"', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] },
{ open: '/**', close: ' */', notIn: ['string'] }
],
}));
}
}
const mode = new ElectricMode();
usingCursor({
text: [
'little goat',
'little LAMB',
'little sheep',
'Big LAMB'
],
languageIdentifier: mode.getLanguageIdentifier()
}, (model, cursor) => {
model.forceTokenization(model.getLineCount());
assertType(model, cursor, 1, 4, '"', '"', `does not double quote when ending with open`);
model.forceTokenization(model.getLineCount());
assertType(model, cursor, 2, 4, '"', '"', `does not double quote when ending with open`);
model.forceTokenization(model.getLineCount());
assertType(model, cursor, 3, 4, '"', '"', `does not double quote when ending with open`);
model.forceTokenization(model.getLineCount());
assertType(model, cursor, 4, 2, '"', '""', `double quote when ending with open`);
model.forceTokenization(model.getLineCount());
assertType(model, cursor, 4, 3, '"', '"', `does not double quote when ending with open`);
});
mode.dispose();
});
test('issue #27937: Trying to add an item to the front of a list is cumbersome', () => {
let mode = new AutoClosingMode();
usingCursor({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册