Merge VS Code 1.31.1 (#4283)

This commit is contained in:
Matt Irvine
2019-03-15 13:09:45 -07:00
committed by GitHub
parent 7d31575149
commit 86bac90001
1716 changed files with 53308 additions and 48375 deletions

View File

@@ -54,6 +54,10 @@ export class InsertCursorAbove extends EditorAction {
}
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
if (!editor.hasModel()) {
return;
}
const useLogicalLine = (args && args.logicalLine === true);
const cursors = editor._getCursors();
const context = cursors.context;
@@ -99,6 +103,10 @@ export class InsertCursorBelow extends EditorAction {
}
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
if (!editor.hasModel()) {
return;
}
const useLogicalLine = (args && args.logicalLine === true);
const cursors = editor._getCursors();
const context = cursors.context;
@@ -154,6 +162,10 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction {
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (!editor.hasModel()) {
return;
}
const model = editor.getModel();
const selections = editor.getSelections();
let newSelections: Selection[] = [];
@@ -177,10 +189,14 @@ class InsertCursorAtEndOfLineSelected extends EditorAction {
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (!editor.hasModel()) {
return;
}
const selections = editor.getSelections();
const lineCount = editor.getModel().getLineCount();
let newSelections = [];
let newSelections: Selection[] = [];
for (let i = selections[0].startLineNumber; i <= lineCount; i++) {
newSelections.push(new Selection(i, selections[0].startColumn, i, selections[0].endColumn));
}
@@ -203,9 +219,13 @@ class InsertCursorAtTopOfLineSelected extends EditorAction {
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (!editor.hasModel()) {
return;
}
const selections = editor.getSelections();
let newSelections = [];
let newSelections: Selection[] = [];
for (let i = selections[0].startLineNumber; i >= 1; i--) {
newSelections.push(new Selection(i, selections[0].startColumn, i, selections[0].endColumn));
}
@@ -226,7 +246,10 @@ export class MultiCursorSessionResult {
export class MultiCursorSession {
public static create(editor: ICodeEditor, findController: CommonFindController): MultiCursorSession {
public static create(editor: ICodeEditor, findController: CommonFindController): MultiCursorSession | null {
if (!editor.hasModel()) {
return null;
}
const findState = findController.getState();
// Find widget owns entirely what we search for if:
@@ -281,10 +304,14 @@ export class MultiCursorSession {
public readonly searchText: string,
public readonly wholeWord: boolean,
public readonly matchCase: boolean,
public currentMatch: Selection
public currentMatch: Selection | null
) { }
public addSelectionToNextFindMatch(): MultiCursorSessionResult {
public addSelectionToNextFindMatch(): MultiCursorSessionResult | null {
if (!this._editor.hasModel()) {
return null;
}
const nextMatch = this._getNextMatch();
if (!nextMatch) {
return null;
@@ -294,7 +321,11 @@ export class MultiCursorSession {
return new MultiCursorSessionResult(allSelections.concat(nextMatch), nextMatch, ScrollType.Smooth);
}
public moveSelectionToNextFindMatch(): MultiCursorSessionResult {
public moveSelectionToNextFindMatch(): MultiCursorSessionResult | null {
if (!this._editor.hasModel()) {
return null;
}
const nextMatch = this._getNextMatch();
if (!nextMatch) {
return null;
@@ -304,7 +335,11 @@ export class MultiCursorSession {
return new MultiCursorSessionResult(allSelections.slice(0, allSelections.length - 1).concat(nextMatch), nextMatch, ScrollType.Smooth);
}
private _getNextMatch(): Selection {
private _getNextMatch(): Selection | null {
if (!this._editor.hasModel()) {
return null;
}
if (this.currentMatch) {
const result = this.currentMatch;
this.currentMatch = null;
@@ -323,7 +358,11 @@ export class MultiCursorSession {
return new Selection(nextMatch.range.startLineNumber, nextMatch.range.startColumn, nextMatch.range.endLineNumber, nextMatch.range.endColumn);
}
public addSelectionToPreviousFindMatch(): MultiCursorSessionResult {
public addSelectionToPreviousFindMatch(): MultiCursorSessionResult | null {
if (!this._editor.hasModel()) {
return null;
}
const previousMatch = this._getPreviousMatch();
if (!previousMatch) {
return null;
@@ -333,7 +372,11 @@ export class MultiCursorSession {
return new MultiCursorSessionResult(allSelections.concat(previousMatch), previousMatch, ScrollType.Smooth);
}
public moveSelectionToPreviousFindMatch(): MultiCursorSessionResult {
public moveSelectionToPreviousFindMatch(): MultiCursorSessionResult | null {
if (!this._editor.hasModel()) {
return null;
}
const previousMatch = this._getPreviousMatch();
if (!previousMatch) {
return null;
@@ -343,7 +386,11 @@ export class MultiCursorSession {
return new MultiCursorSessionResult(allSelections.slice(0, allSelections.length - 1).concat(previousMatch), previousMatch, ScrollType.Smooth);
}
private _getPreviousMatch(): Selection {
private _getPreviousMatch(): Selection | null {
if (!this._editor.hasModel()) {
return null;
}
if (this.currentMatch) {
const result = this.currentMatch;
this.currentMatch = null;
@@ -363,6 +410,10 @@ export class MultiCursorSession {
}
public selectAll(): FindMatch[] {
if (!this._editor.hasModel()) {
return [];
}
this.findController.highlightFindOptions();
return this._editor.getModel().findMatches(this.searchText, true, false, this.matchCase, this.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false, Constants.MAX_SAFE_SMALL_INTEGER);
@@ -375,7 +426,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
private readonly _editor: ICodeEditor;
private _ignoreSelectionChange: boolean;
private _session: MultiCursorSession;
private _session: MultiCursorSession | null;
private _sessionDispose: IDisposable[];
public static get(editor: ICodeEditor): MultiCursorSelectionController {
@@ -466,7 +517,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
return new Selection(selection.startLineNumber, word.startColumn, selection.startLineNumber, word.endColumn);
}
private _applySessionResult(result: MultiCursorSessionResult): void {
private _applySessionResult(result: MultiCursorSessionResult | null): void {
if (!result) {
return;
}
@@ -476,11 +527,14 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
}
}
public getSession(findController: CommonFindController): MultiCursorSession {
public getSession(findController: CommonFindController): MultiCursorSession | null {
return this._session;
}
public addSelectionToNextFindMatch(findController: CommonFindController): void {
if (!this._editor.hasModel()) {
return;
}
if (!this._session) {
// If there are multiple cursors, handle the case where they do not all select the same text.
const allSelections = this._editor.getSelections();
@@ -527,6 +581,10 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
}
public selectAll(findController: CommonFindController): void {
if (!this._editor.hasModel()) {
return;
}
let matches: FindMatch[] | null = null;
const findState = findController.getState();
@@ -578,7 +636,7 @@ export abstract class MultiCursorSelectionControllerAction extends EditorAction
}
const findController = CommonFindController.get(editor);
if (!findController) {
return null;
return;
}
this._run(multiCursorController, findController);
}
@@ -715,9 +773,9 @@ export class CompatChangeAll extends MultiCursorSelectionControllerAction {
class SelectionHighlighterState {
public readonly searchText: string;
public readonly matchCase: boolean;
public readonly wordSeparators: string;
public readonly wordSeparators: string | null;
constructor(searchText: string, matchCase: boolean, wordSeparators: string) {
constructor(searchText: string, matchCase: boolean, wordSeparators: string | null) {
this.searchText = searchText;
this.matchCase = matchCase;
this.wordSeparators = wordSeparators;
@@ -726,7 +784,7 @@ class SelectionHighlighterState {
/**
* Everything equals except for `lastWordUnderCursor`
*/
public static softEquals(a: SelectionHighlighterState, b: SelectionHighlighterState): boolean {
public static softEquals(a: SelectionHighlighterState | null, b: SelectionHighlighterState | null): boolean {
if (!a && !b) {
return true;
}
@@ -748,7 +806,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
private _isEnabled: boolean;
private decorations: string[];
private updateSoon: RunOnceScheduler;
private state: SelectionHighlighterState;
private state: SelectionHighlighterState | null;
constructor(editor: ICodeEditor) {
super();
@@ -800,12 +858,11 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
this._setState(SelectionHighlighter._createState(this._isEnabled, this.editor));
}
private static _createState(isEnabled: boolean, editor: ICodeEditor): SelectionHighlighterState {
private static _createState(isEnabled: boolean, editor: ICodeEditor): SelectionHighlighterState | null {
if (!isEnabled) {
return null;
}
const model = editor.getModel();
if (!model) {
if (!editor.hasModel()) {
return null;
}
const s = editor.getSelection();
@@ -877,7 +934,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
return new SelectionHighlighterState(r.searchText, r.matchCase, r.wholeWord ? editor.getConfiguration().wordSeparators : null);
}
private _setState(state: SelectionHighlighterState): void {
private _setState(state: SelectionHighlighterState | null): void {
if (SelectionHighlighterState.softEquals(this.state, state)) {
this.state = state;
return;
@@ -889,6 +946,10 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
return;
}
if (!this.editor.hasModel()) {
return;
}
const model = this.editor.getModel();
if (model.isTooLargeForTokenization()) {
// the file is too large, so searching word under cursor in the whole document takes is blocking the UI.

View File

@@ -24,7 +24,7 @@ suite('Multicursor', () => {
let addCursorUpAction = new InsertCursorAbove();
editor.setSelection(new Selection(2, 1, 2, 1));
addCursorUpAction.run(null, editor, {});
addCursorUpAction.run(null!, editor, {});
assert.equal(cursor.getSelections().length, 2);
editor.trigger('test', Handler.Paste, {
@@ -35,8 +35,8 @@ suite('Multicursor', () => {
]
});
// cursorCommand(cursor, H.Paste, { text: '1\n2' });
assert.equal(editor.getModel().getLineContent(1), '1abc');
assert.equal(editor.getModel().getLineContent(2), '2def');
assert.equal(editor.getModel()!.getLineContent(1), '1abc');
assert.equal(editor.getModel()!.getLineContent(2), '2def');
});
});
@@ -45,7 +45,7 @@ suite('Multicursor', () => {
'abc'
], {}, (editor, cursor) => {
let addCursorDownAction = new InsertCursorBelow();
addCursorDownAction.run(null, editor, {});
addCursorDownAction.run(null!, editor, {});
assert.equal(cursor.getSelections().length, 1);
});
});
@@ -65,9 +65,9 @@ suite('Multicursor selection', () => {
onWillSaveState: Event.None,
get: (key: string) => queryState[key],
getBoolean: (key: string) => !!queryState[key],
getInteger: (key: string) => undefined,
getInteger: (key: string) => undefined!,
store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); },
remove: (key) => void 0
remove: (key) => undefined
} as IStorageService);
test('issue #8817: Cursor position changes when you cancel multicursor', () => {
@@ -83,8 +83,8 @@ suite('Multicursor selection', () => {
editor.setSelection(new Selection(2, 9, 2, 16));
selectHighlightsAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
selectHighlightsAction.run(null!, editor);
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[2, 9, 2, 16],
[1, 9, 1, 16],
[3, 9, 3, 16],
@@ -92,7 +92,7 @@ suite('Multicursor selection', () => {
editor.trigger('test', 'removeSecondaryCursors', null);
assert.deepEqual(fromRange(editor.getSelection()), [2, 9, 2, 16]);
assert.deepEqual(fromRange(editor.getSelection()!), [2, 9, 2, 16]);
multiCursorSelectController.dispose();
findController.dispose();
@@ -114,8 +114,8 @@ suite('Multicursor selection', () => {
editor.setSelection(new Selection(1, 1, 1, 1));
findController.getState().change({ searchString: 'some+thing', isRegex: true, isRevealed: true }, false);
selectHighlightsAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
selectHighlightsAction.run(null!, editor);
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[1, 1, 1, 10],
[2, 1, 2, 11],
[3, 1, 3, 12],
@@ -147,15 +147,15 @@ suite('Multicursor selection', () => {
editor.setSelection(new Selection(2, 1, 3, 4));
addSelectionToNextFindMatch.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
addSelectionToNextFindMatch.run(null!, editor);
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[2, 1, 3, 4],
[8, 1, 9, 4]
]);
editor.trigger('test', 'removeSecondaryCursors', null);
assert.deepEqual(fromRange(editor.getSelection()), [2, 1, 3, 4]);
assert.deepEqual(fromRange(editor.getSelection()!), [2, 1, 3, 4]);
multiCursorSelectController.dispose();
findController.dispose();
@@ -175,16 +175,16 @@ suite('Multicursor selection', () => {
editor.setSelection(new Selection(1, 1, 1, 4));
addSelectionToNextFindMatch.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
addSelectionToNextFindMatch.run(null!, editor);
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[1, 1, 1, 4],
[1, 4, 1, 7]
]);
addSelectionToNextFindMatch.run(null, editor);
addSelectionToNextFindMatch.run(null, editor);
addSelectionToNextFindMatch.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
addSelectionToNextFindMatch.run(null!, editor);
addSelectionToNextFindMatch.run(null!, editor);
addSelectionToNextFindMatch.run(null!, editor);
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[1, 1, 1, 4],
[1, 4, 1, 7],
[2, 1, 2, 4],
@@ -193,7 +193,7 @@ suite('Multicursor selection', () => {
]);
editor.trigger('test', Handler.Type, { text: 'z' });
assert.deepEqual(editor.getSelections().map(fromRange), [
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[1, 2, 1, 2],
[1, 3, 1, 3],
[2, 2, 2, 2],
@@ -224,7 +224,7 @@ suite('Multicursor selection', () => {
'rty'
], { serviceCollection: serviceCollection }, (editor, cursor) => {
editor.getModel().setEOL(EndOfLineSequence.CRLF);
editor.getModel()!.setEOL(EndOfLineSequence.CRLF);
let findController = editor.registerAndInstantiateContribution<CommonFindController>(CommonFindController);
let multiCursorSelectController = editor.registerAndInstantiateContribution<MultiCursorSelectionController>(MultiCursorSelectionController);
@@ -232,15 +232,15 @@ suite('Multicursor selection', () => {
editor.setSelection(new Selection(2, 1, 3, 4));
addSelectionToNextFindMatch.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
addSelectionToNextFindMatch.run(null!, editor);
assert.deepEqual(editor.getSelections()!.map(fromRange), [
[2, 1, 3, 4],
[8, 1, 9, 4]
]);
editor.trigger('test', 'removeSecondaryCursors', null);
assert.deepEqual(fromRange(editor.getSelection()), [2, 1, 3, 4]);
assert.deepEqual(fromRange(editor.getSelection()!), [2, 1, 3, 4]);
multiCursorSelectController.dispose();
findController.dispose();
@@ -277,25 +277,25 @@ suite('Multicursor selection', () => {
new Selection(1, 2, 1, 2),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
new Selection(3, 1, 3, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
@@ -316,20 +316,20 @@ suite('Multicursor selection', () => {
new Selection(2, 2, 2, 2),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
new Selection(3, 1, 3, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
@@ -350,20 +350,20 @@ suite('Multicursor selection', () => {
new Selection(2, 1, 2, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
new Selection(3, 1, 3, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
@@ -385,14 +385,14 @@ suite('Multicursor selection', () => {
new Selection(3, 1, 3, 1),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
new Selection(3, 1, 3, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
@@ -414,14 +414,14 @@ suite('Multicursor selection', () => {
new Selection(3, 6, 3, 6),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 5, 1, 10),
new Selection(2, 5, 2, 10),
new Selection(3, 5, 3, 8),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 5, 1, 10),
new Selection(2, 5, 2, 10),
@@ -443,20 +443,20 @@ suite('Multicursor selection', () => {
new Selection(1, 1, 1, 5),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 5),
new Selection(2, 1, 2, 5),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 5),
new Selection(2, 1, 2, 5),
new Selection(3, 1, 3, 5),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 5),
new Selection(2, 1, 2, 5),
@@ -464,7 +464,7 @@ suite('Multicursor selection', () => {
new Selection(4, 1, 4, 5),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 5),
new Selection(2, 1, 2, 5),
@@ -473,7 +473,7 @@ suite('Multicursor selection', () => {
new Selection(5, 1, 5, 5),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 5),
new Selection(2, 1, 2, 5),
@@ -501,18 +501,18 @@ suite('Multicursor selection', () => {
new Selection(1, 2, 1, 2),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(4, 1, 4, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(4, 1, 4, 4),
@@ -527,12 +527,12 @@ suite('Multicursor selection', () => {
new Selection(1, 2, 1, 2),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(4, 1, 4, 4),
@@ -543,7 +543,7 @@ suite('Multicursor selection', () => {
new Selection(1, 1, 1, 4),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(2, 1, 2, 4),
@@ -558,14 +558,14 @@ suite('Multicursor selection', () => {
new Selection(1, 2, 1, 2),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(4, 1, 4, 4),
new Selection(6, 2, 6, 5),
]);
action.run(null, editor);
action.run(null!, editor);
assert.deepEqual(editor.getSelections(), [
new Selection(1, 1, 1, 4),
new Selection(4, 1, 4, 4),