Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -2,25 +2,24 @@
* 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 nls from 'vs/nls';
import * as strings from 'vs/base/common/strings';
import { onUnexpectedError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import * as strings from 'vs/base/common/strings';
import { CursorCollection } from 'vs/editor/common/controller/cursorCollection';
import { CursorColumns, CursorConfiguration, CursorContext, CursorState, EditOperationResult, EditOperationType, IColumnSelectData, ICursors, PartialCursorState, RevealTarget } from 'vs/editor/common/controller/cursorCommon';
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection, SelectionDirection, ISelection } from 'vs/editor/common/core/selection';
import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { CursorColumns, CursorConfiguration, EditOperationResult, CursorContext, CursorState, RevealTarget, IColumnSelectData, ICursors, EditOperationType } from 'vs/editor/common/controller/cursorCommon';
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
import { IIdentifiedSingleEditOperation, ITextModel, TrackedRangeStickiness } from 'vs/editor/common/model';
import { RawContentChangedType } from 'vs/editor/common/model/textModelEvents';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { Event, Emitter } from 'vs/base/common/event';
import { ITextModel, IIdentifiedSingleEditOperation, TrackedRangeStickiness } from 'vs/editor/common/model';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
function containsLineMappingChanged(events: viewEvents.ViewEvent[]): boolean {
for (let i = 0, len = events.length; i < len; i++) {
@@ -66,7 +65,7 @@ export class CursorModelState {
this.cursorState = cursor.getAll();
}
public equals(other: CursorModelState): boolean {
public equals(other: CursorModelState | null): boolean {
if (!other) {
return false;
}
@@ -107,7 +106,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
private _isHandling: boolean;
private _isDoingComposition: boolean;
private _columnSelectData: IColumnSelectData;
private _columnSelectData: IColumnSelectData | null;
private _prevEditOperationType: EditOperationType;
constructor(configuration: editorCommon.IConfiguration, model: ITextModel, viewModel: IViewModel) {
@@ -192,8 +191,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return this._cursors.getAll();
}
public setStates(source: string, reason: CursorChangeReason, states: CursorState[]): void {
if (states.length > Cursor.MAX_CURSOR_COUNT) {
public setStates(source: string, reason: CursorChangeReason, states: PartialCursorState[] | null): void {
if (states !== null && states.length > Cursor.MAX_CURSOR_COUNT) {
states = states.slice(0, Cursor.MAX_CURSOR_COUNT);
this._onDidReachMaxCursorCount.fire(void 0);
}
@@ -348,7 +347,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
// ------ auxiliary handling logic
private _executeEditOperation(opResult: EditOperationResult): void {
private _executeEditOperation(opResult: EditOperationResult | null): void {
if (!opResult) {
// Nothing to execute
@@ -372,7 +371,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}
}
private _interpretCommandResult(cursorState: Selection[]): void {
private _interpretCommandResult(cursorState: Selection[] | null): void {
if (!cursorState || cursorState.length === 0) {
cursorState = this._cursors.readSelectionFromMarkers();
}
@@ -385,7 +384,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
// -----------------------------------------------------------------------------------------------------------
// ----- emitting events
private _emitStateChangedIfNecessary(source: string, reason: CursorChangeReason, oldState: CursorModelState): boolean {
private _emitStateChangedIfNecessary(source: string, reason: CursorChangeReason, oldState: CursorModelState | null): boolean {
const newState = new CursorModelState(this._model, this);
if (newState.equals(oldState)) {
return false;
@@ -620,7 +619,7 @@ interface ICommandsData {
class CommandExecutor {
public static executeCommands(model: ITextModel, selectionsBefore: Selection[], commands: editorCommon.ICommand[]): Selection[] {
public static executeCommands(model: ITextModel, selectionsBefore: Selection[], commands: (editorCommon.ICommand | null)[]): Selection[] | null {
const ctx: IExecContext = {
model: model,
@@ -638,7 +637,7 @@ class CommandExecutor {
return result;
}
private static _innerExecuteCommands(ctx: IExecContext, commands: editorCommon.ICommand[]): Selection[] {
private static _innerExecuteCommands(ctx: IExecContext, commands: (editorCommon.ICommand | null)[]): Selection[] | null {
if (this._arrayIsEmpty(commands)) {
return null;
@@ -661,7 +660,7 @@ class CommandExecutor {
// Remove operations belonging to losing cursors
let filteredOperations: IIdentifiedSingleEditOperation[] = [];
for (let i = 0, len = rawOperations.length; i < len; i++) {
if (!loserCursorsMap.hasOwnProperty(rawOperations[i].identifier.major.toString())) {
if (!loserCursorsMap.hasOwnProperty(rawOperations[i].identifier!.major.toString())) {
filteredOperations.push(rawOperations[i]);
}
}
@@ -671,7 +670,7 @@ class CommandExecutor {
if (commandsData.hadTrackedEditOperation && filteredOperations.length > 0) {
filteredOperations[0]._isTracked = true;
}
const selectionsAfter = ctx.model.pushEditOperations(ctx.selectionsBefore, filteredOperations, (inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] => {
let selectionsAfter = ctx.model.pushEditOperations(ctx.selectionsBefore, filteredOperations, (inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] => {
let groupedInverseEditOperations: IIdentifiedSingleEditOperation[][] = [];
for (let i = 0; i < ctx.selectionsBefore.length; i++) {
groupedInverseEditOperations[i] = [];
@@ -685,20 +684,20 @@ class CommandExecutor {
groupedInverseEditOperations[op.identifier.major].push(op);
}
const minorBasedSorter = (a: IIdentifiedSingleEditOperation, b: IIdentifiedSingleEditOperation) => {
return a.identifier.minor - b.identifier.minor;
return a.identifier!.minor - b.identifier!.minor;
};
let cursorSelections: Selection[] = [];
for (let i = 0; i < ctx.selectionsBefore.length; i++) {
if (groupedInverseEditOperations[i].length > 0) {
groupedInverseEditOperations[i].sort(minorBasedSorter);
cursorSelections[i] = commands[i].computeCursorState(ctx.model, {
cursorSelections[i] = commands[i]!.computeCursorState(ctx.model, {
getInverseEditOperations: () => {
return groupedInverseEditOperations[i];
},
getTrackedSelection: (id: string) => {
const idx = parseInt(id, 10);
const range = ctx.model._getTrackedRange(ctx.trackedRanges[idx]);
const range = ctx.model._getTrackedRange(ctx.trackedRanges[idx])!;
if (ctx.trackedRangesDirection[idx] === SelectionDirection.LTR) {
return new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
}
@@ -711,6 +710,9 @@ class CommandExecutor {
}
return cursorSelections;
});
if (!selectionsAfter) {
selectionsAfter = ctx.selectionsBefore;
}
// Extract losing cursors
let losingCursors: number[] = [];
@@ -733,7 +735,7 @@ class CommandExecutor {
return selectionsAfter;
}
private static _arrayIsEmpty(commands: editorCommon.ICommand[]): boolean {
private static _arrayIsEmpty(commands: (editorCommon.ICommand | null)[]): boolean {
for (let i = 0, len = commands.length; i < len; i++) {
if (commands[i]) {
return false;
@@ -742,13 +744,14 @@ class CommandExecutor {
return true;
}
private static _getEditOperations(ctx: IExecContext, commands: editorCommon.ICommand[]): ICommandsData {
private static _getEditOperations(ctx: IExecContext, commands: (editorCommon.ICommand | null)[]): ICommandsData {
let operations: IIdentifiedSingleEditOperation[] = [];
let hadTrackedEditOperation: boolean = false;
for (let i = 0, len = commands.length; i < len; i++) {
if (commands[i]) {
const r = this._getEditOperationsFromCommand(ctx, i, commands[i]);
const command = commands[i];
if (command) {
const r = this._getEditOperationsFromCommand(ctx, i, command);
operations = operations.concat(r.operations);
hadTrackedEditOperation = hadTrackedEditOperation || r.hadTrackedEditOperation;
}
@@ -765,7 +768,7 @@ class CommandExecutor {
let operations: IIdentifiedSingleEditOperation[] = [];
let operationMinor = 0;
const addEditOperation = (selection: Range, text: string) => {
const addEditOperation = (selection: Range, text: string | null) => {
if (selection.isEmpty() && text === '') {
// This command wants to add a no-op => no thank you
return;
@@ -783,7 +786,7 @@ class CommandExecutor {
};
let hadTrackedEditOperation = false;
const addTrackedEditOperation = (selection: Range, text: string) => {
const addTrackedEditOperation = (selection: Range, text: string | null) => {
hadTrackedEditOperation = true;
addEditOperation(selection, text);
};
@@ -861,17 +864,17 @@ class CommandExecutor {
let loserMajor: number;
if (previousOp.identifier.major > currentOp.identifier.major) {
if (previousOp.identifier!.major > currentOp.identifier!.major) {
// previousOp loses the battle
loserMajor = previousOp.identifier.major;
loserMajor = previousOp.identifier!.major;
} else {
loserMajor = currentOp.identifier.major;
loserMajor = currentOp.identifier!.major;
}
loserCursorsMap[loserMajor.toString()] = true;
for (let j = 0; j < operations.length; j++) {
if (operations[j].identifier.major === loserMajor) {
if (operations[j].identifier!.major === loserMajor) {
operations.splice(j, 1);
if (j < i) {
i--;