mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 09:35:38 -05:00
Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches * A few more merges * Post npm install * Fix batch of build breaks * Fix more build breaks * Fix more build errors * Fix more build breaks * Runtime fixes 1 * Get connection dialog working with some todos * Fix a few packaging issues * Copy several node_modules to package build to fix loader issues * Fix breaks from master * A few more fixes * Make tests pass * First pass of license header updates * Second pass of license header updates * Fix restore dialog issues * Remove add additional themes menu items * fix select box issues where the list doesn't show up * formatting * Fix editor dispose issue * Copy over node modules to correct location on all platforms
This commit is contained in:
@@ -20,6 +20,7 @@ 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';
|
||||
|
||||
function containsLineMappingChanged(events: viewEvents.ViewEvent[]): boolean {
|
||||
for (let i = 0, len = events.length; i < len; i++) {
|
||||
@@ -60,7 +61,7 @@ export class CursorModelState {
|
||||
public readonly modelVersionId: number;
|
||||
public readonly cursorState: CursorState[];
|
||||
|
||||
constructor(model: editorCommon.IModel, cursor: Cursor) {
|
||||
constructor(model: ITextModel, cursor: Cursor) {
|
||||
this.modelVersionId = model.getVersionId();
|
||||
this.cursorState = cursor.getAll();
|
||||
}
|
||||
@@ -90,7 +91,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
public readonly onDidChange: Event<CursorStateChangedEvent> = this._onDidChange.event;
|
||||
|
||||
private readonly _configuration: editorCommon.IConfiguration;
|
||||
private readonly _model: editorCommon.IModel;
|
||||
private readonly _model: ITextModel;
|
||||
private _knownModelVersionId: number;
|
||||
private readonly _viewModel: IViewModel;
|
||||
public context: CursorContext;
|
||||
private _cursors: CursorCollection;
|
||||
@@ -100,10 +102,11 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
private _columnSelectData: IColumnSelectData;
|
||||
private _prevEditOperationType: EditOperationType;
|
||||
|
||||
constructor(configuration: editorCommon.IConfiguration, model: editorCommon.IModel, viewModel: IViewModel) {
|
||||
constructor(configuration: editorCommon.IConfiguration, model: ITextModel, viewModel: IViewModel) {
|
||||
super();
|
||||
this._configuration = configuration;
|
||||
this._model = model;
|
||||
this._knownModelVersionId = this._model.getVersionId();
|
||||
this._viewModel = viewModel;
|
||||
this.context = new CursorContext(this._configuration, this._model, this._viewModel);
|
||||
this._cursors = new CursorCollection(this.context);
|
||||
@@ -114,6 +117,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
this._prevEditOperationType = EditOperationType.Other;
|
||||
|
||||
this._register(this._model.onDidChangeRawContent((e) => {
|
||||
this._knownModelVersionId = e.versionId;
|
||||
if (this._isHandling) {
|
||||
return;
|
||||
}
|
||||
@@ -127,6 +131,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._knownModelVersionId !== this._model.getVersionId()) {
|
||||
// There are model change events that I didn't yet receive.
|
||||
//
|
||||
// This can happen when editing the model, and the view model receives the change events first,
|
||||
// and the view model emits line mapping changed events, all before the cursor gets a chance to
|
||||
// recover from markers.
|
||||
//
|
||||
// The model change listener above will be called soon and we'll ensure a valid cursor state there.
|
||||
return;
|
||||
}
|
||||
// Ensure valid state
|
||||
this.setStates('viewModel', CursorChangeReason.NotSet, this.getAll());
|
||||
}));
|
||||
@@ -135,13 +149,13 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
this.context = new CursorContext(this._configuration, this._model, this._viewModel);
|
||||
this._cursors.updateContext(this.context);
|
||||
};
|
||||
this._register(model.onDidChangeLanguage((e) => {
|
||||
this._register(this._model.onDidChangeLanguage((e) => {
|
||||
updateCursorContext();
|
||||
}));
|
||||
this._register(model.onDidChangeLanguageConfiguration(() => {
|
||||
this._register(this._model.onDidChangeLanguageConfiguration(() => {
|
||||
updateCursorContext();
|
||||
}));
|
||||
this._register(model.onDidChangeOptions(() => {
|
||||
this._register(this._model.onDidChangeOptions(() => {
|
||||
updateCursorContext();
|
||||
}));
|
||||
this._register(this._configuration.onDidChange((e) => {
|
||||
@@ -328,11 +342,6 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._configuration.editor.readOnly) {
|
||||
// Cannot execute when read only
|
||||
return;
|
||||
}
|
||||
|
||||
if (opResult.shouldPushStackElementBefore) {
|
||||
this._model.pushStackElement();
|
||||
}
|
||||
@@ -369,20 +378,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
let isInEditableRange: boolean = true;
|
||||
if (this._model.hasEditableRange()) {
|
||||
const editableRange = this._model.getEditableRange();
|
||||
if (!editableRange.containsPosition(newState.cursorState[0].modelState.position)) {
|
||||
isInEditableRange = false;
|
||||
}
|
||||
}
|
||||
|
||||
const selections = this._cursors.getSelections();
|
||||
const viewSelections = this._cursors.getViewSelections();
|
||||
|
||||
// Let the view get the event first.
|
||||
this._emit([new viewEvents.ViewCursorStateChangedEvent(viewSelections, isInEditableRange)]);
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewCursorStateChangedEvent(viewSelections));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
|
||||
// Only after the view has been notified, let the rest of the world know...
|
||||
if (!oldState
|
||||
@@ -424,7 +429,12 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
}
|
||||
|
||||
public emitCursorRevealRange(viewRange: Range, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) {
|
||||
this._emit([new viewEvents.ViewRevealRangeRequestEvent(viewRange, verticalType, revealHorizontal, scrollType)]);
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(viewRange, verticalType, revealHorizontal, scrollType));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
@@ -443,6 +453,12 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._configuration.editor.readOnly) {
|
||||
// All the remaining handlers will try to edit the model,
|
||||
// but we cannot edit when read only...
|
||||
return;
|
||||
}
|
||||
|
||||
const oldState = new CursorModelState(this._model, this);
|
||||
let cursorChangeReason = CursorChangeReason.NotSet;
|
||||
|
||||
@@ -463,7 +479,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
|
||||
case H.Paste:
|
||||
cursorChangeReason = CursorChangeReason.Paste;
|
||||
this._paste(<string>payload.text, <boolean>payload.pasteOnNewLine);
|
||||
this._paste(<string>payload.text, <boolean>payload.pasteOnNewLine, <string[]>payload.multicursorText);
|
||||
break;
|
||||
|
||||
case H.Cut:
|
||||
@@ -526,8 +542,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text, replaceCharCnt));
|
||||
}
|
||||
|
||||
private _paste(text: string, pasteOnNewLine: boolean): void {
|
||||
this._executeEditOperation(TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), pasteOnNewLine, text));
|
||||
private _paste(text: string, pasteOnNewLine: boolean, multicursorText: string[]): void {
|
||||
this._executeEditOperation(TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), text, pasteOnNewLine, multicursorText));
|
||||
}
|
||||
|
||||
private _cut(): void {
|
||||
@@ -552,25 +568,25 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
||||
}
|
||||
|
||||
interface IExecContext {
|
||||
readonly model: editorCommon.IModel;
|
||||
readonly model: ITextModel;
|
||||
readonly selectionsBefore: Selection[];
|
||||
readonly trackedRanges: string[];
|
||||
readonly trackedRangesDirection: SelectionDirection[];
|
||||
}
|
||||
|
||||
interface ICommandData {
|
||||
operations: editorCommon.IIdentifiedSingleEditOperation[];
|
||||
operations: IIdentifiedSingleEditOperation[];
|
||||
hadTrackedEditOperation: boolean;
|
||||
}
|
||||
|
||||
interface ICommandsData {
|
||||
operations: editorCommon.IIdentifiedSingleEditOperation[];
|
||||
operations: IIdentifiedSingleEditOperation[];
|
||||
hadTrackedEditOperation: boolean;
|
||||
}
|
||||
|
||||
class CommandExecutor {
|
||||
|
||||
public static executeCommands(model: editorCommon.IModel, selectionsBefore: Selection[], commands: editorCommon.ICommand[]): Selection[] {
|
||||
public static executeCommands(model: ITextModel, selectionsBefore: Selection[], commands: editorCommon.ICommand[]): Selection[] {
|
||||
|
||||
const ctx: IExecContext = {
|
||||
model: model,
|
||||
@@ -582,7 +598,7 @@ class CommandExecutor {
|
||||
const result = this._innerExecuteCommands(ctx, commands);
|
||||
|
||||
for (let i = 0, len = ctx.trackedRanges.length; i < len; i++) {
|
||||
ctx.model._setTrackedRange(ctx.trackedRanges[i], null, editorCommon.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges);
|
||||
ctx.model._setTrackedRange(ctx.trackedRanges[i], null, TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -601,17 +617,6 @@ class CommandExecutor {
|
||||
|
||||
const rawOperations = commandsData.operations;
|
||||
|
||||
const editableRange = ctx.model.getEditableRange();
|
||||
const editableRangeStart = editableRange.getStartPosition();
|
||||
const editableRangeEnd = editableRange.getEndPosition();
|
||||
for (let i = 0, len = rawOperations.length; i < len; i++) {
|
||||
const operationRange = rawOperations[i].range;
|
||||
if (!editableRangeStart.isBeforeOrEqual(operationRange.getStartPosition()) || !operationRange.getEndPosition().isBeforeOrEqual(editableRangeEnd)) {
|
||||
// These commands are outside of the editable range
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const loserCursorsMap = this._getLoserCursorMap(rawOperations);
|
||||
if (loserCursorsMap.hasOwnProperty('0')) {
|
||||
// These commands are very messed up
|
||||
@@ -620,7 +625,7 @@ class CommandExecutor {
|
||||
}
|
||||
|
||||
// Remove operations belonging to losing cursors
|
||||
let filteredOperations: editorCommon.IIdentifiedSingleEditOperation[] = [];
|
||||
let filteredOperations: IIdentifiedSingleEditOperation[] = [];
|
||||
for (let i = 0, len = rawOperations.length; i < len; i++) {
|
||||
if (!loserCursorsMap.hasOwnProperty(rawOperations[i].identifier.major.toString())) {
|
||||
filteredOperations.push(rawOperations[i]);
|
||||
@@ -632,8 +637,8 @@ class CommandExecutor {
|
||||
if (commandsData.hadTrackedEditOperation && filteredOperations.length > 0) {
|
||||
filteredOperations[0]._isTracked = true;
|
||||
}
|
||||
const selectionsAfter = ctx.model.pushEditOperations(ctx.selectionsBefore, filteredOperations, (inverseEditOperations: editorCommon.IIdentifiedSingleEditOperation[]): Selection[] => {
|
||||
let groupedInverseEditOperations: editorCommon.IIdentifiedSingleEditOperation[][] = [];
|
||||
const selectionsAfter = ctx.model.pushEditOperations(ctx.selectionsBefore, filteredOperations, (inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] => {
|
||||
let groupedInverseEditOperations: IIdentifiedSingleEditOperation[][] = [];
|
||||
for (let i = 0; i < ctx.selectionsBefore.length; i++) {
|
||||
groupedInverseEditOperations[i] = [];
|
||||
}
|
||||
@@ -645,7 +650,7 @@ class CommandExecutor {
|
||||
}
|
||||
groupedInverseEditOperations[op.identifier.major].push(op);
|
||||
}
|
||||
const minorBasedSorter = (a: editorCommon.IIdentifiedSingleEditOperation, b: editorCommon.IIdentifiedSingleEditOperation) => {
|
||||
const minorBasedSorter = (a: IIdentifiedSingleEditOperation, b: IIdentifiedSingleEditOperation) => {
|
||||
return a.identifier.minor - b.identifier.minor;
|
||||
};
|
||||
let cursorSelections: Selection[] = [];
|
||||
@@ -704,7 +709,7 @@ class CommandExecutor {
|
||||
}
|
||||
|
||||
private static _getEditOperations(ctx: IExecContext, commands: editorCommon.ICommand[]): ICommandsData {
|
||||
let operations: editorCommon.IIdentifiedSingleEditOperation[] = [];
|
||||
let operations: IIdentifiedSingleEditOperation[] = [];
|
||||
let hadTrackedEditOperation: boolean = false;
|
||||
|
||||
for (let i = 0, len = commands.length; i < len; i++) {
|
||||
@@ -723,7 +728,7 @@ class CommandExecutor {
|
||||
private static _getEditOperationsFromCommand(ctx: IExecContext, majorIdentifier: number, command: editorCommon.ICommand): ICommandData {
|
||||
// This method acts as a transaction, if the command fails
|
||||
// everything it has done is ignored
|
||||
let operations: editorCommon.IIdentifiedSingleEditOperation[] = [];
|
||||
let operations: IIdentifiedSingleEditOperation[] = [];
|
||||
let operationMinor = 0;
|
||||
|
||||
const addEditOperation = (selection: Range, text: string) => {
|
||||
@@ -750,25 +755,25 @@ class CommandExecutor {
|
||||
};
|
||||
|
||||
const trackSelection = (selection: Selection, trackPreviousOnEmpty?: boolean) => {
|
||||
let stickiness: editorCommon.TrackedRangeStickiness;
|
||||
let stickiness: TrackedRangeStickiness;
|
||||
if (selection.isEmpty()) {
|
||||
if (typeof trackPreviousOnEmpty === 'boolean') {
|
||||
if (trackPreviousOnEmpty) {
|
||||
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
|
||||
stickiness = TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
|
||||
} else {
|
||||
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
|
||||
stickiness = TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
|
||||
}
|
||||
} else {
|
||||
// Try to lock it with surrounding text
|
||||
const maxLineColumn = ctx.model.getLineMaxColumn(selection.startLineNumber);
|
||||
if (selection.startColumn === maxLineColumn) {
|
||||
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
|
||||
stickiness = TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
|
||||
} else {
|
||||
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
|
||||
stickiness = TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stickiness = editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
|
||||
stickiness = TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
|
||||
}
|
||||
|
||||
const l = ctx.trackedRanges.length;
|
||||
@@ -801,12 +806,12 @@ class CommandExecutor {
|
||||
};
|
||||
}
|
||||
|
||||
private static _getLoserCursorMap(operations: editorCommon.IIdentifiedSingleEditOperation[]): { [index: string]: boolean; } {
|
||||
private static _getLoserCursorMap(operations: IIdentifiedSingleEditOperation[]): { [index: string]: boolean; } {
|
||||
// This is destructive on the array
|
||||
operations = operations.slice(0);
|
||||
|
||||
// Sort operations with last one first
|
||||
operations.sort((a: editorCommon.IIdentifiedSingleEditOperation, b: editorCommon.IIdentifiedSingleEditOperation): number => {
|
||||
operations.sort((a: IIdentifiedSingleEditOperation, b: IIdentifiedSingleEditOperation): number => {
|
||||
// Note the minus!
|
||||
return -(Range.compareRangesUsingEnds(a.range, b.range));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user