mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from master
This commit is contained in:
@@ -2,19 +2,18 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ShiftCommand } from 'vs/editor/common/commands/shiftCommand';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { getEditOperation, testCommand } from 'vs/editor/test/browser/testCommand';
|
||||
import { withEditorModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
|
||||
/**
|
||||
* Create single edit operation
|
||||
@@ -39,34 +38,7 @@ class DocBlockCommentMode extends MockMode {
|
||||
['[', ']']
|
||||
],
|
||||
|
||||
onEnterRules: [
|
||||
{
|
||||
// e.g. /** | */
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
},
|
||||
{
|
||||
// e.g. /** ...|
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction: IndentAction.None, appendText: ' * ' }
|
||||
},
|
||||
{
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction: IndentAction.None, appendText: '* ' }
|
||||
},
|
||||
{
|
||||
// e.g. */|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
},
|
||||
{
|
||||
// e.g. *-----*/|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
}
|
||||
]
|
||||
onEnterRules: javascriptOnEnterRules
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,18 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Cursor } from 'vs/editor/common/controller/cursor';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
|
||||
import { Cursor } from 'vs/editor/common/controller/cursor';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
|
||||
function testCommand(lines: string[], selections: Selection[], edits: IIdentifiedSingleEditOperation[], expectedLines: string[], expectedSelections: Selection[]): void {
|
||||
withTestCodeEditor(lines, {}, (editor, cursor) => {
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { TrimTrailingWhitespaceCommand, trimTrailingWhitespace } from 'vs/editor/common/commands/trimTrailingWhitespaceCommand';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import { getEditOperation } from 'vs/editor/test/browser/testCommand';
|
||||
import { withEditorModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { CoreEditingCommands, CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
|
||||
import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Handler, ICommand, IEditOperationBuilder, ICursorStateComputerData } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLinePreference, ITextModel, EndOfLineSequence } from 'vs/editor/common/model';
|
||||
import { TokenizationResult2 } from 'vs/editor/common/core/token';
|
||||
import { Handler, ICommand, ICursorStateComputerData, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLinePreference, EndOfLineSequence, ITextModel } from 'vs/editor/common/model';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { IState, ITokenizationSupport, LanguageIdentifier, TokenizationRegistry } from 'vs/editor/common/modes';
|
||||
import { IndentAction, IndentationRule } from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { LanguageIdentifier, ITokenizationSupport, IState, TokenizationRegistry } from 'vs/editor/common/modes';
|
||||
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
|
||||
import { CoreNavigationCommands, CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
|
||||
import { NULL_STATE } from 'vs/editor/common/modes/nullMode';
|
||||
import { TokenizationResult2 } from 'vs/editor/common/core/token';
|
||||
import { createTextModel, IRelaxedTextModelCreationOptions } from 'vs/editor/test/common/editorTestUtils';
|
||||
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { IRelaxedTextModelCreationOptions, createTextModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
|
||||
const H = Handler;
|
||||
|
||||
@@ -1105,14 +1105,13 @@ class SurroundingMode extends MockMode {
|
||||
class OnEnterMode extends MockMode {
|
||||
private static readonly _id = new LanguageIdentifier('onEnterMode', 3);
|
||||
|
||||
constructor(indentAction: IndentAction, outdentCurrentLine?: boolean) {
|
||||
constructor(indentAction: IndentAction) {
|
||||
super(OnEnterMode._id);
|
||||
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {
|
||||
onEnterRules: [{
|
||||
beforeText: /.*/,
|
||||
action: {
|
||||
indentAction: indentAction,
|
||||
outdentCurrentLine: outdentCurrentLine
|
||||
indentAction: indentAction
|
||||
}
|
||||
}]
|
||||
}));
|
||||
@@ -1869,7 +1868,7 @@ suite('Editor Controller - Regression tests', () => {
|
||||
this.timeout(10000);
|
||||
const LINE_CNT = 2000;
|
||||
|
||||
let text = [];
|
||||
let text: string[] = [];
|
||||
for (let i = 0; i < LINE_CNT; i++) {
|
||||
text[i] = 'asd';
|
||||
}
|
||||
@@ -2385,7 +2384,7 @@ suite('Editor Controller - Cursor Configuration', () => {
|
||||
|
||||
class TestCommand implements ICommand {
|
||||
|
||||
private _selectionId: string = null;
|
||||
private _selectionId: string | null = null;
|
||||
|
||||
public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
|
||||
builder.addEditOperation(new Range(1, 13, 1, 14), '');
|
||||
@@ -3517,31 +3516,7 @@ suite('Editor Controller - Indentation Rules', () => {
|
||||
// ^.*\{[^}"']*$
|
||||
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/
|
||||
},
|
||||
onEnterRules: [
|
||||
{
|
||||
// e.g. /** | */
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
}, {
|
||||
// e.g. /** ...|
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction: IndentAction.None, appendText: ' * ' }
|
||||
}, {
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction: IndentAction.None, appendText: '* ' }
|
||||
}, {
|
||||
// e.g. */|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
},
|
||||
{
|
||||
// e.g. *-----*/|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
|
||||
action: { indentAction: IndentAction.None, removeText: 1 }
|
||||
}
|
||||
]
|
||||
onEnterRules: javascriptOnEnterRules
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -3849,7 +3824,7 @@ suite('ElectricCharacter', () => {
|
||||
languageIdentifier: mode.getLanguageIdentifier()
|
||||
}, (model, cursor) => {
|
||||
moveTo(cursor, 1, 5);
|
||||
let changeText: string = null;
|
||||
let changeText: string | null = null;
|
||||
model.onDidChangeContent(e => {
|
||||
changeText = e.changes[0].text;
|
||||
});
|
||||
@@ -3947,6 +3922,21 @@ suite('autoClosingPairs', () => {
|
||||
],
|
||||
}));
|
||||
}
|
||||
|
||||
public setAutocloseEnabledSet(chars: string) {
|
||||
this._register(LanguageConfigurationRegistry.register(this.getLanguageIdentifier(), {
|
||||
autoCloseBefore: chars,
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
|
||||
{ open: '\"', close: '\"', notIn: ['string'] },
|
||||
{ open: '`', close: '`', notIn: ['string', 'comment'] },
|
||||
{ open: '/**', close: ' */', notIn: ['string'] }
|
||||
],
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const enum ColumnType {
|
||||
@@ -3982,7 +3972,7 @@ suite('autoClosingPairs', () => {
|
||||
cursorCommand(cursor, H.Undo);
|
||||
}
|
||||
|
||||
test('open parens', () => {
|
||||
test('open parens: default', () => {
|
||||
let mode = new AutoClosingMode();
|
||||
usingCursor({
|
||||
text: [
|
||||
@@ -3998,6 +3988,52 @@ suite('autoClosingPairs', () => {
|
||||
languageIdentifier: mode.getLanguageIdentifier()
|
||||
}, (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})`);
|
||||
} else {
|
||||
assertType(model, cursor, lineNumber, column, '(', '(', `does not auto close @ (${lineNumber}, ${column})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
mode.dispose();
|
||||
});
|
||||
|
||||
test('open parens: whitespace', () => {
|
||||
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: 'beforeWhitespace'
|
||||
}
|
||||
}, (model, cursor) => {
|
||||
|
||||
let autoClosePositions = [
|
||||
'var| a| =| [|];|',
|
||||
'var| b| =| `asd`;|',
|
||||
@@ -4025,6 +4061,259 @@ suite('autoClosingPairs', () => {
|
||||
mode.dispose();
|
||||
});
|
||||
|
||||
test('open parens disabled/enabled open quotes enabled/disabled', () => {
|
||||
let mode = new AutoClosingMode();
|
||||
usingCursor({
|
||||
text: [
|
||||
'var a = [];',
|
||||
],
|
||||
languageIdentifier: mode.getLanguageIdentifier(),
|
||||
editorOpts: {
|
||||
autoClosingBrackets: 'beforeWhitespace',
|
||||
autoClosingQuotes: 'never'
|
||||
}
|
||||
}, (model, cursor) => {
|
||||
|
||||
let autoClosePositions = [
|
||||
'var| a| =| [|];|',
|
||||
];
|
||||
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})`);
|
||||
}
|
||||
assertType(model, cursor, lineNumber, column, '\'', '\'', `does not auto close @ (${lineNumber}, ${column})`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
usingCursor({
|
||||
text: [
|
||||
'var b = [];',
|
||||
],
|
||||
languageIdentifier: mode.getLanguageIdentifier(),
|
||||
editorOpts: {
|
||||
autoClosingBrackets: 'never',
|
||||
autoClosingQuotes: 'beforeWhitespace'
|
||||
}
|
||||
}, (model, cursor) => {
|
||||
|
||||
let autoClosePositions = [
|
||||
'var b =| [|];|',
|
||||
];
|
||||
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})`);
|
||||
}
|
||||
assertType(model, cursor, lineNumber, column, '(', '(', `does not auto close @ (${lineNumber}, ${column})`);
|
||||
}
|
||||
}
|
||||
});
|
||||
mode.dispose();
|
||||
});
|
||||
|
||||
test('configurable open parens', () => {
|
||||
let mode = new AutoClosingMode();
|
||||
mode.setAutocloseEnabledSet('abc');
|
||||
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: 'languageDefined'
|
||||
}
|
||||
}, (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: 'never',
|
||||
autoClosingQuotes: 'never'
|
||||
}
|
||||
}, (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`');
|
||||
|
||||
// type a (
|
||||
cursorCommand(cursor, H.Type, { text: '(' }, 'keyboard');
|
||||
|
||||
assert.equal(model.getValue(), '`(var)` a = `(asd)`');
|
||||
});
|
||||
|
||||
usingCursor({
|
||||
text: [
|
||||
'var a = asd'
|
||||
],
|
||||
languageIdentifier: mode.getLanguageIdentifier(),
|
||||
editorOpts: {
|
||||
autoSurround: 'never'
|
||||
}
|
||||
}, (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');
|
||||
});
|
||||
|
||||
usingCursor({
|
||||
text: [
|
||||
'var a = asd'
|
||||
],
|
||||
languageIdentifier: mode.getLanguageIdentifier(),
|
||||
editorOpts: {
|
||||
autoSurround: 'quotes'
|
||||
}
|
||||
}, (model, cursor) => {
|
||||
|
||||
cursor.setSelections('test', [
|
||||
new Selection(1, 1, 1, 4),
|
||||
]);
|
||||
|
||||
// type a `
|
||||
cursorCommand(cursor, H.Type, { text: '`' }, 'keyboard');
|
||||
assert.equal(model.getValue(), '`var` a = asd');
|
||||
|
||||
// type a (
|
||||
cursorCommand(cursor, H.Type, { text: '(' }, 'keyboard');
|
||||
assert.equal(model.getValue(), '`(` a = asd');
|
||||
});
|
||||
|
||||
usingCursor({
|
||||
text: [
|
||||
'var a = asd'
|
||||
],
|
||||
languageIdentifier: mode.getLanguageIdentifier(),
|
||||
editorOpts: {
|
||||
autoSurround: 'brackets'
|
||||
}
|
||||
}, (model, cursor) => {
|
||||
|
||||
cursor.setSelections('test', [
|
||||
new Selection(1, 1, 1, 4),
|
||||
]);
|
||||
|
||||
// type a (
|
||||
cursorCommand(cursor, H.Type, { text: '(' }, 'keyboard');
|
||||
assert.equal(model.getValue(), '(var) a = asd');
|
||||
|
||||
// type a `
|
||||
cursorCommand(cursor, H.Type, { text: '`' }, 'keyboard');
|
||||
assert.equal(model.getValue(), '(`) a = asd');
|
||||
});
|
||||
mode.dispose();
|
||||
});
|
||||
|
||||
test('quote', () => {
|
||||
let mode = new AutoClosingMode();
|
||||
usingCursor({
|
||||
@@ -4042,14 +4331,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;
|
||||
@@ -4070,6 +4359,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({
|
||||
@@ -4222,7 +4556,7 @@ suite('autoClosingPairs', () => {
|
||||
cursorCommand(cursor, H.ReplacePreviousChar, { replaceCharCnt: 1, text: '"' }, 'keyboard');
|
||||
cursorCommand(cursor, H.CompositionEnd, null, 'keyboard');
|
||||
|
||||
assert.equal(model.getValue(), '\'""\'');
|
||||
assert.equal(model.getValue(), '\'"\'');
|
||||
|
||||
// Typing ' + space after '
|
||||
model.setValue('\'');
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { Cursor } from 'vs/editor/common/controller/cursor';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
import { CursorMove } from 'vs/editor/common/controller/cursorMoveCommands';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
|
||||
suite('Cursor move command test', () => {
|
||||
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TextAreaInput, ITextAreaInputHost } from 'vs/editor/browser/controller/textAreaInput';
|
||||
import { ISimpleModel, TextAreaState, PagedScreenReaderStrategy } from 'vs/editor/browser/controller/textAreaState';
|
||||
import { Range, IRange } from 'vs/editor/common/core/range';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { createFastDomNode } from 'vs/base/browser/fastDomNode';
|
||||
import * as browser from 'vs/base/browser/browser';
|
||||
import { createFastDomNode } from 'vs/base/browser/fastDomNode';
|
||||
import { ITextAreaInputHost, TextAreaInput } from 'vs/editor/browser/controller/textAreaInput';
|
||||
import { ISimpleModel, PagedScreenReaderStrategy, TextAreaState } from 'vs/editor/browser/controller/textAreaState';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { EndOfLinePreference } from 'vs/editor/common/model';
|
||||
|
||||
// To run this test, open imeTester.html
|
||||
@@ -101,7 +100,7 @@ function doCreateTest(description: string, inputStr: string, expectedStr: string
|
||||
return PagedScreenReaderStrategy.fromEditorSelection(currentState, model, selection, true);
|
||||
},
|
||||
deduceModelPosition: (viewAnchorPosition: Position, deltaOffset: number, lineFeedCnt: number): Position => {
|
||||
return null;
|
||||
return null!;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { TextAreaState, ITextAreaWrapper, PagedScreenReaderStrategy } from 'vs/editor/browser/controller/textAreaState';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { ITextAreaWrapper, PagedScreenReaderStrategy, TextAreaState } from 'vs/editor/browser/controller/textAreaState';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
|
||||
export class MockTextAreaWrapper extends Disposable implements ITextAreaWrapper {
|
||||
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { EditorState, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { CodeEditorStateFlag, EditorState } from 'vs/editor/browser/core/editorState';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
|
||||
interface IStubEditorState {
|
||||
model?: { uri?: URI, version?: number };
|
||||
|
||||
@@ -2,28 +2,26 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { IModelDecorationOptions } from 'vs/editor/common/model';
|
||||
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
|
||||
import { AbstractCodeEditorService } from 'vs/editor/browser/services/abstractCodeEditorService';
|
||||
import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { AbstractCodeEditorService } from 'vs/editor/browser/services/abstractCodeEditorService';
|
||||
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
|
||||
import { IModelDecorationOptions } from 'vs/editor/common/model';
|
||||
import { CommandsRegistry, ICommandEvent, ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IResourceInput } from 'vs/platform/editor/common/editor';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export class TestCodeEditorService extends AbstractCodeEditorService {
|
||||
public lastInput: IResourceInput;
|
||||
public getActiveCodeEditor(): ICodeEditor { return null; }
|
||||
public openCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise<ICodeEditor> {
|
||||
public getActiveCodeEditor(): ICodeEditor | null { return null; }
|
||||
public openCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Thenable<ICodeEditor | null> {
|
||||
this.lastInput = input;
|
||||
return TPromise.as(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
public registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void { }
|
||||
public removeDecorationType(key: string): void { }
|
||||
public resolveDecorationOptions(decorationTypeKey: string, writable: boolean): IModelDecorationOptions { return null; }
|
||||
public resolveDecorationOptions(decorationTypeKey: string, writable: boolean): IModelDecorationOptions { return {}; }
|
||||
}
|
||||
|
||||
export class TestCommandService implements ICommandService {
|
||||
@@ -38,18 +36,18 @@ export class TestCommandService implements ICommandService {
|
||||
this._instantiationService = instantiationService;
|
||||
}
|
||||
|
||||
public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
|
||||
public executeCommand<T>(id: string, ...args: any[]): Promise<T> {
|
||||
const command = CommandsRegistry.getCommand(id);
|
||||
if (!command) {
|
||||
return TPromise.wrapError<T>(new Error(`command '${id}' not found`));
|
||||
return Promise.reject(new Error(`command '${id}' not found`));
|
||||
}
|
||||
|
||||
try {
|
||||
this._onWillExecuteCommand.fire({ commandId: id });
|
||||
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
|
||||
return TPromise.as(result);
|
||||
return Promise.resolve(result);
|
||||
} catch (err) {
|
||||
return TPromise.wrapError<T>(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,21 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { CodeEditorServiceImpl } from 'vs/editor/browser/services/codeEditorServiceImpl';
|
||||
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
|
||||
import { IResourceInput } from 'vs/platform/editor/common/editor';
|
||||
import { TestTheme, TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
|
||||
const themeServiceMock = new TestThemeService();
|
||||
|
||||
// {{SQL CARBON EDIT}} - Remove exported test class
|
||||
suite('Decoration Render Options', () => {
|
||||
test('register and resolve decoration type', () => {
|
||||
// {{SQL CARBON EDIT}} - Remove test
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,14 +2,11 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import * as assert from 'assert';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { TestCodeEditorService } from 'vs/editor/test/browser/editorTestServices';
|
||||
import { ICommandService, NullCommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { OpenerService } from 'vs/editor/browser/services/openerService';
|
||||
import { TestCodeEditorService } from 'vs/editor/test/browser/editorTestServices';
|
||||
import { CommandsRegistry, ICommandService, NullCommandService } from 'vs/platform/commands/common/commands';
|
||||
|
||||
suite('OpenerService', function () {
|
||||
|
||||
@@ -20,9 +17,9 @@ suite('OpenerService', function () {
|
||||
const commandService = new class implements ICommandService {
|
||||
_serviceBrand: any;
|
||||
onWillExecuteCommand = () => ({ dispose: () => { } });
|
||||
executeCommand(id: string, ...args: any[]): TPromise<any> {
|
||||
executeCommand(id: string, ...args: any[]): Promise<any> {
|
||||
lastCommand = { id, args };
|
||||
return TPromise.as(undefined);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,4 +103,4 @@ suite('OpenerService', function () {
|
||||
assert.equal(lastCommand.args[0], 12);
|
||||
assert.equal(lastCommand.args[1], true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,28 +2,29 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { View } from 'vs/editor/browser/view/viewImpl';
|
||||
import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
|
||||
import * as editorOptions from 'vs/editor/common/config/editorOptions';
|
||||
import { Cursor } from 'vs/editor/common/controller/cursor';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
import * as editorOptions from 'vs/editor/common/config/editorOptions';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { CodeEditorWidget, ICodeEditorWidgetOptions, } from 'vs/editor/browser/widget/codeEditorWidget';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
|
||||
import { TestCodeEditorService, TestCommandService } from 'vs/editor/test/browser/editorTestServices';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
|
||||
export class TestCodeEditor extends CodeEditorWidget implements editorBrowser.ICodeEditor {
|
||||
|
||||
@@ -31,14 +32,15 @@ export class TestCodeEditor extends CodeEditorWidget implements editorBrowser.IC
|
||||
protected _createConfiguration(options: editorOptions.IEditorOptions): editorCommon.IConfiguration {
|
||||
return new TestConfiguration(options);
|
||||
}
|
||||
protected _createView(): void {
|
||||
protected _createView(viewModel: ViewModel, cursor: Cursor): [View, boolean] {
|
||||
// Never create a view
|
||||
return [null! as View, false];
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region Testing utils
|
||||
public getCursor(): Cursor {
|
||||
return this.cursor;
|
||||
public getCursor(): Cursor | undefined {
|
||||
return this._modelData ? this._modelData.cursor : undefined;
|
||||
}
|
||||
public registerAndInstantiateContribution<T extends editorCommon.IEditorContribution>(ctor: any): T {
|
||||
let r = <T>this._instantiationService.createInstance(ctor, this);
|
||||
@@ -47,19 +49,18 @@ export class TestCodeEditor extends CodeEditorWidget implements editorBrowser.IC
|
||||
}
|
||||
public dispose() {
|
||||
super.dispose();
|
||||
if (this.model) {
|
||||
this.model.dispose();
|
||||
this.model = null;
|
||||
if (this._modelData) {
|
||||
this._modelData.model.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestEditorDomElement {
|
||||
parentElement: IContextKeyServiceTarget = null;
|
||||
parentElement: IContextKeyServiceTarget | null = null;
|
||||
setAttribute(attr: string, value: string): void { }
|
||||
removeAttribute(attr: string): void { }
|
||||
hasAttribute(attr: string): boolean { return false; }
|
||||
getAttribute(attr: string): string { return undefined; }
|
||||
getAttribute(attr: string): string | undefined { return undefined; }
|
||||
addEventListener(event: string): void { }
|
||||
removeEventListener(event: string): void { }
|
||||
}
|
||||
@@ -72,10 +73,14 @@ export interface TestCodeEditorCreationOptions extends editorOptions.IEditorOpti
|
||||
serviceCollection?: ServiceCollection;
|
||||
}
|
||||
|
||||
export function withTestCodeEditor(text: string[], options: TestCodeEditorCreationOptions, callback: (editor: TestCodeEditor, cursor: Cursor) => void): void {
|
||||
export function withTestCodeEditor(text: string | string[], options: TestCodeEditorCreationOptions, callback: (editor: TestCodeEditor, cursor: Cursor | undefined) => void): void {
|
||||
// create a model if necessary and remember it in order to dispose it.
|
||||
if (!options.model) {
|
||||
options.model = TextModel.createFromString(text.join('\n'));
|
||||
if (typeof text === 'string') {
|
||||
options.model = TextModel.createFromString(text);
|
||||
} else {
|
||||
options.model = TextModel.createFromString(text.join('\n'));
|
||||
}
|
||||
}
|
||||
|
||||
let editor = <TestCodeEditor>createTestCodeEditor(options);
|
||||
|
||||
@@ -2,16 +2,15 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { ITextModel, IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
|
||||
export function testCommand(
|
||||
lines: string[],
|
||||
@@ -22,7 +21,10 @@ export function testCommand(
|
||||
expectedSelection: Selection
|
||||
): void {
|
||||
let model = TextModel.createFromString(lines.join('\n'), undefined, languageIdentifier);
|
||||
withTestCodeEditor(null, { model: model }, (editor, cursor) => {
|
||||
withTestCodeEditor('', { model: model }, (_editor, cursor) => {
|
||||
if (!cursor) {
|
||||
return;
|
||||
}
|
||||
|
||||
cursor.setSelections('tests', [selection]);
|
||||
|
||||
@@ -59,7 +61,7 @@ export function getEditOperation(model: ITextModel, command: editorCommon.IComma
|
||||
|
||||
|
||||
trackSelection: (selection: Selection) => {
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
};
|
||||
command.getEditOperations(model, editOperationBuilder);
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Constants, MinimapCharRenderer } from 'vs/editor/common/view/minimapCharRenderer';
|
||||
import { MinimapCharRendererFactory } from 'vs/editor/test/common/view/minimapCharRendererFactory';
|
||||
import { getOrCreateMinimapCharRenderer } from 'vs/editor/common/view/runtimeMinimapCharRenderer';
|
||||
import { RGBA8 } from 'vs/editor/common/core/rgba';
|
||||
import { Constants, MinimapCharRenderer } from 'vs/editor/common/view/minimapCharRenderer';
|
||||
import { getOrCreateMinimapCharRenderer } from 'vs/editor/common/view/runtimeMinimapCharRenderer';
|
||||
import { MinimapCharRendererFactory } from 'vs/editor/test/common/view/minimapCharRendererFactory';
|
||||
|
||||
let canvas = <HTMLCanvasElement>document.getElementById('my-canvas');
|
||||
let ctx = canvas.getContext('2d');
|
||||
let ctx = canvas.getContext('2d')!;
|
||||
|
||||
canvas.style.height = 100 + 'px';
|
||||
canvas.height = 100;
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { RenderedLinesCollection, ILine } from 'vs/editor/browser/view/viewLayer';
|
||||
import { ILine, RenderedLinesCollection } from 'vs/editor/browser/view/viewLayer';
|
||||
|
||||
class TestLine implements ILine {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user