提交 034871d8 编写于 作者: A Alex Dima

Fixes #41825: Special handling of quotes in surround selection

上级 f251d22e
......@@ -579,6 +579,8 @@ export class TypeOperations {
return false;
}
const isTypingAQuoteCharacter = (ch === '\'' || ch === '"');
for (let i = 0, len = selections.length; i < len; i++) {
const selection = selections[i];
......@@ -603,6 +605,15 @@ export class TypeOperations {
if (selectionContainsOnlyWhitespace) {
return false;
}
if (isTypingAQuoteCharacter && selection.startLineNumber === selection.endLineNumber && selection.startColumn + 1 === selection.endColumn) {
const selectionText = model.getValueInRange(selection);
if ((selectionText === '\'' || selectionText === '"')) {
// Typing a quote character on top of another quote character
// => disable surround selection type
return false;
}
}
}
return true;
......
......@@ -1220,7 +1220,7 @@ suite('Editor Controller - Regression tests', () => {
constructor() {
super(languageId);
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {
surroundingPairs: [{ open: '"', close: '"' }]
surroundingPairs: [{ open: '%', close: '%' }]
}));
}
}
......@@ -1231,8 +1231,8 @@ suite('Editor Controller - Regression tests', () => {
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
editor.setSelection(new Selection(1, 1, 1, 2));
cursorCommand(cursor, H.Type, { text: '"' }, 'keyboard');
assert.equal(model.getValue(EndOfLinePreference.LF), '"\'"👁\'', 'assert1');
cursorCommand(cursor, H.Type, { text: '%' }, 'keyboard');
assert.equal(model.getValue(EndOfLinePreference.LF), '%\'%👁\'', 'assert1');
cursorCommand(cursor, H.Undo, {});
assert.equal(model.getValue(EndOfLinePreference.LF), '\'👁\'', 'assert2');
......@@ -4159,6 +4159,43 @@ suite('autoClosingPairs', () => {
mode.dispose();
});
test('issue #41825: Special handling of quotes in surrounding pairs', () => {
const languageId = new LanguageIdentifier('myMode', 3);
class MyMode extends MockMode {
constructor() {
super(languageId);
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {
surroundingPairs: [
{ open: '"', close: '"' },
{ open: '\'', close: '\'' },
]
}));
}
}
const mode = new MyMode();
const model = createTextModel('var x = \'hi\';', undefined, languageId);
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
editor.setSelections([
new Selection(1, 9, 1, 10),
new Selection(1, 12, 1, 13)
]);
cursorCommand(cursor, H.Type, { text: '"' }, 'keyboard');
assert.equal(model.getValue(EndOfLinePreference.LF), 'var x = "hi";', 'assert1');
editor.setSelections([
new Selection(1, 9, 1, 10),
new Selection(1, 12, 1, 13)
]);
cursorCommand(cursor, H.Type, { text: '\'' }, 'keyboard');
assert.equal(model.getValue(EndOfLinePreference.LF), 'var x = \'hi\';', 'assert2');
});
model.dispose();
mode.dispose();
});
test('All cursors should do the same thing when deleting left', () => {
let mode = new AutoClosingMode();
let model = createTextModel(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册