提交 8ad23858 编写于 作者: J Jackson Kearl

tests and bug fixes

上级 7be7e2f8
......@@ -1600,7 +1600,7 @@ export class EditorOptionsValidator {
const _autoClosingOptions = (config: any, defaultValue: EditorAutoClosingOptions): EditorAutoClosingOptions => {
if (typeof config === 'boolean') { return { autoClose: config, autoWrap: config, enabledBefore: ' \t\n' }; }
if (!config) { config = {}; }
let copy: EditorAutoClosingOptions = { autoClose: defaultValue.autoClose, autoWrap: defaultValue.autoWrap, enabledBefore: defaultValue.enabledBefore };
if (typeof config.autoClose === 'boolean') { copy.autoClose = config.autoClose; }
if (typeof config.autoWrap === 'boolean') { copy.autoWrap = config.autoWrap; }
......
......@@ -65,7 +65,7 @@ export class DeleteOperations {
const lineText = model.getLineContent(position.lineNumber);
const character = lineText[position.column - 2];
const characterIsQuote = (character === '\'' || character === '"');
const characterIsQuote = (character === '\'' || character === '"' || character === '`');
const autoCloseConfig = characterIsQuote ? config.autoClosingQuotes : config.autoClosingBrackets;
if (!config.autoClosingPairsOpen.hasOwnProperty(character) || !(autoCloseConfig.autoWrap || autoCloseConfig.autoClose)) {
......
......@@ -437,7 +437,7 @@ export class TypeOperations {
}
private static _isAutoClosingCloseCharType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
const chIsQuote = (ch === '\'' || ch === '"');
const chIsQuote = (ch === '\'' || ch === '"' || ch === '`');
const autoCloseConfig = chIsQuote ? config.autoClosingQuotes : config.autoClosingBrackets;
if (!autoCloseConfig.autoClose || !config.autoClosingPairsClose.hasOwnProperty(ch)) {
......@@ -514,7 +514,7 @@ export class TypeOperations {
}
private static _isAutoClosingOpenCharType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
const chIsQuote = (ch === '\'' || ch === '"');
const chIsQuote = (ch === '\'' || ch === '"' || ch === '`');
const autoCloseConfig = chIsQuote ? config.autoClosingQuotes : config.autoClosingBrackets;
if (!autoCloseConfig.autoClose || !config.autoClosingPairsOpen.hasOwnProperty(ch)) {
return false;
......@@ -587,7 +587,7 @@ export class TypeOperations {
}
private static _isSurroundSelectionType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
const chIsQuote = (ch === '\'' || ch === '"');
const chIsQuote = (ch === '\'' || ch === '"' || ch === '`');
const autoCloseConfig = chIsQuote ? config.autoClosingQuotes : config.autoClosingBrackets;
if (!autoCloseConfig.autoWrap || !config.surroundingPairs.hasOwnProperty(ch)) {
return false;
......@@ -620,7 +620,7 @@ export class TypeOperations {
if (chIsQuote && selection.startLineNumber === selection.endLineNumber && selection.startColumn + 1 === selection.endColumn) {
const selectionText = model.getValueInRange(selection);
if ((selectionText === '\'' || selectionText === '"')) {
if ((selectionText === '\'' || selectionText === '"' || selectionText === '`')) {
// Typing a quote character on top of another quote character
// => disable surround selection type
return false;
......
......@@ -3999,14 +3999,14 @@ suite('autoClosingPairs', () => {
}, (model, cursor) => {
let autoClosePositions = [
'var| a| =| [|];|',
'var| b| =| `asd`;|',
'var| c| =| \'asd\';|',
'var| d| =| "asd";|',
'var| e| =| /*3*/| 3;|',
'var| f| =| /**| 3| */3;|',
'var| g| =| (3+5|);|',
'var| h| =| {| a:| \'value\'| |};|',
'var| a| =| [|]|;|',
'var| b| =| `asd`|;|',
'var| c| =| \'asd\'|;|',
'var| d| =| "asd"|;|',
'var| e| =| /*3*/| 3|;|',
'var| f| =| /**| 3| */3|;|',
'var| g| =| (3+5|)|;|',
'var| h| =| {| a|:| \'value\'| |}|;|',
];
for (let i = 0, len = autoClosePositions.length; i < len; i++) {
const lineNumber = i + 1;
......@@ -4025,6 +4025,159 @@ suite('autoClosingPairs', () => {
mode.dispose();
});
test('configurable open parens', () => {
let mode = new AutoClosingMode();
usingCursor({
text: [
'var a = [];',
'var b = `asd`;',
'var c = \'asd\';',
'var d = "asd";',
'var e = /*3*/ 3;',
'var f = /** 3 */3;',
'var g = (3+5);',
'var h = { a: \'value\' };',
],
languageIdentifier: mode.getLanguageIdentifier(),
editorOpts: {
autoClosingBrackets: {
enabledBefore: 'abc',
autoClose: true,
autoWrap: true
}
}
}, (model, cursor) => {
let autoClosePositions = [
'v|ar |a = [|];|',
'v|ar |b = `|asd`;|',
'v|ar |c = \'|asd\';|',
'v|ar d = "|asd";|',
'v|ar e = /*3*/ 3;|',
'v|ar f = /** 3 */3;|',
'v|ar g = (3+5|);|',
'v|ar h = { |a: \'v|alue\' |};|',
];
for (let i = 0, len = autoClosePositions.length; i < len; i++) {
const lineNumber = i + 1;
const autoCloseColumns = extractSpecialColumns(model.getLineMaxColumn(lineNumber), autoClosePositions[i]);
for (let column = 1; column < autoCloseColumns.length; column++) {
model.forceTokenization(lineNumber);
if (autoCloseColumns[column] === ColumnType.Special1) {
assertType(model, cursor, lineNumber, column, '(', '()', `auto closes @ (${lineNumber}, ${column})`);
} else {
assertType(model, cursor, lineNumber, column, '(', '(', `does not auto close @ (${lineNumber}, ${column})`);
}
}
}
});
mode.dispose();
});
test('auto-pairing can be disabled', () => {
let mode = new AutoClosingMode();
usingCursor({
text: [
'var a = [];',
'var b = `asd`;',
'var c = \'asd\';',
'var d = "asd";',
'var e = /*3*/ 3;',
'var f = /** 3 */3;',
'var g = (3+5);',
'var h = { a: \'value\' };',
],
languageIdentifier: mode.getLanguageIdentifier(),
editorOpts: {
autoClosingBrackets: {
enabledBefore: 'abc',
autoClose: false,
autoWrap: true
},
autoClosingQuotes: {
enabledBefore: 'abc',
autoClose: false,
autoWrap: true
}
}
}, (model, cursor) => {
let autoClosePositions = [
'var a = [];',
'var b = `asd`;',
'var c = \'asd\';',
'var d = "asd";',
'var e = /*3*/ 3;',
'var f = /** 3 */3;',
'var g = (3+5);',
'var h = { a: \'value\' };',
];
for (let i = 0, len = autoClosePositions.length; i < len; i++) {
const lineNumber = i + 1;
const autoCloseColumns = extractSpecialColumns(model.getLineMaxColumn(lineNumber), autoClosePositions[i]);
for (let column = 1; column < autoCloseColumns.length; column++) {
model.forceTokenization(lineNumber);
if (autoCloseColumns[column] === ColumnType.Special1) {
assertType(model, cursor, lineNumber, column, '(', '()', `auto closes @ (${lineNumber}, ${column})`);
assertType(model, cursor, lineNumber, column, '"', '""', `auto closes @ (${lineNumber}, ${column})`);
} else {
assertType(model, cursor, lineNumber, column, '(', '(', `does not auto close @ (${lineNumber}, ${column})`);
assertType(model, cursor, lineNumber, column, '"', '"', `does not auto close @ (${lineNumber}, ${column})`);
}
}
}
});
mode.dispose();
});
test('auto wrapping is configurable', () => {
let mode = new AutoClosingMode();
usingCursor({
text: [
'var a = asd'
],
languageIdentifier: mode.getLanguageIdentifier()
}, (model, cursor) => {
cursor.setSelections('test', [
new Selection(1, 1, 1, 4),
new Selection(1, 9, 1, 12),
]);
// type a `
cursorCommand(cursor, H.Type, { text: '`' }, 'keyboard');
assert.equal(model.getValue(), '`var` a = `asd`');
});
usingCursor({
text: [
'var a = asd'
],
languageIdentifier: mode.getLanguageIdentifier(),
editorOpts: {
autoClosingBrackets: {
autoWrap: false,
autoClose: true,
enabledBefore: ''
}
}
}, (model, cursor) => {
cursor.setSelections('test', [
new Selection(1, 1, 1, 4),
]);
// type a `
cursorCommand(cursor, H.Type, { text: '`' }, 'keyboard');
assert.equal(model.getValue(), '` a = asd');
});
mode.dispose();
});
test('quote', () => {
let mode = new AutoClosingMode();
usingCursor({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册