Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -12,8 +12,7 @@ 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 * as editorCommon from 'vs/editor/common/editorCommon';
import { CursorColumns, CursorConfiguration, EditOperationResult, CursorContext, CursorState, RevealTarget, IColumnSelectData, ICursors } from 'vs/editor/common/controller/cursorCommon';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
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 { TextModelEventType, ModelRawContentChangedEvent, RawContentChangedType } from 'vs/editor/common/model/textModelEvents';
@@ -21,7 +20,6 @@ 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 { ScreenReaderMessageGenerator } from "vs/editor/common/controller/accGenerator";
function containsLineMappingChanged(events: viewEvents.ViewEvent[]): boolean {
for (let i = 0, len = events.length; i < len; i++) {
@@ -100,6 +98,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
private _isHandling: boolean;
private _isDoingComposition: boolean;
private _columnSelectData: IColumnSelectData;
private _prevEditOperationType: EditOperationType;
constructor(configuration: editorCommon.IConfiguration, model: editorCommon.IModel, viewModel: IViewModel) {
super();
@@ -112,6 +111,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._isHandling = false;
this._isDoingComposition = false;
this._columnSelectData = null;
this._prevEditOperationType = EditOperationType.Other;
this._register(this._model.addBulkListener((events) => {
if (this._isHandling) {
@@ -151,11 +151,10 @@ 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(this._model.onDidChangeLanguage((e) => {
this._register(model.onDidChangeLanguage((e) => {
updateCursorContext();
}));
this._register(LanguageConfigurationRegistry.onDidChange(() => {
// TODO@Alex: react only if certain supports changed? (and if my model's mode changed)
this._register(model.onDidChangeLanguageConfiguration(() => {
updateCursorContext();
}));
this._register(model.onDidChangeOptions(() => {
@@ -281,6 +280,9 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}
private _onModelContentChanged(hadFlushEvent: boolean): void {
this._prevEditOperationType = EditOperationType.Other;
if (hadFlushEvent) {
// a model.setValue() was called
this._cursors.dispose();
@@ -325,6 +327,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this.setStates(source, CursorChangeReason.NotSet, CursorState.fromModelSelections(selections));
}
public getPrevEditOperationType(): EditOperationType {
return this._prevEditOperationType;
}
public setPrevEditOperationType(type: EditOperationType): void {
this._prevEditOperationType = type;
}
// ------ auxiliary handling logic
private _executeEditOperation(opResult: EditOperationResult): void {
@@ -347,6 +357,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
if (result) {
// The commands were applied correctly
this._interpretCommandResult(result);
this._prevEditOperationType = opResult.type;
}
if (opResult.shouldPushStackElementAfter) {
@@ -518,16 +530,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}
// Here we must interpret each typed character individually, that's why we create a new context
this._executeEditOperation(TypeOperations.typeWithInterceptors(this.context.config, this.context.model, this.getSelections(), chr));
this._executeEditOperation(TypeOperations.typeWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), chr));
}
} else {
this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this.context.config, this.context.model, this.getSelections(), text));
this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text));
}
}
private _replacePreviousChar(text: string, replaceCharCnt: number): void {
this._executeEditOperation(TypeOperations.replacePreviousChar(this.context.config, this.context.model, this.getSelections(), text, replaceCharCnt));
this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text, replaceCharCnt));
}
private _paste(text: string, pasteOnNewLine: boolean): void {
@@ -541,14 +553,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
private _externalExecuteCommand(command: editorCommon.ICommand): void {
this._cursors.killSecondaryCursors();
this._executeEditOperation(new EditOperationResult([command], {
this._executeEditOperation(new EditOperationResult(EditOperationType.Other, [command], {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
}));
}
private _externalExecuteCommands(commands: editorCommon.ICommand[]): void {
this._executeEditOperation(new EditOperationResult(commands, {
this._executeEditOperation(new EditOperationResult(EditOperationType.Other, commands, {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
}));
@@ -558,8 +570,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
interface IExecContext {
readonly model: editorCommon.IModel;
readonly selectionsBefore: Selection[];
readonly selectionStartMarkers: string[];
readonly positionMarkers: string[];
readonly trackedRanges: string[];
readonly trackedRangesDirection: SelectionDirection[];
}
interface ICommandData {
@@ -579,15 +591,14 @@ class CommandExecutor {
const ctx: IExecContext = {
model: model,
selectionsBefore: selectionsBefore,
selectionStartMarkers: [],
positionMarkers: []
trackedRanges: [],
trackedRangesDirection: []
};
const result = this._innerExecuteCommands(ctx, commands);
for (let i = 0; i < ctx.selectionStartMarkers.length; i++) {
ctx.model._removeMarker(ctx.selectionStartMarkers[i]);
ctx.model._removeMarker(ctx.positionMarkers[i]);
for (let i = 0, len = ctx.trackedRanges.length; i < len; i++) {
ctx.model._setTrackedRange(ctx.trackedRanges[i], null, editorCommon.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges);
}
return result;
@@ -664,9 +675,11 @@ class CommandExecutor {
getTrackedSelection: (id: string) => {
const idx = parseInt(id, 10);
const selectionStartMarker = ctx.model._getMarker(ctx.selectionStartMarkers[idx]);
const positionMarker = ctx.model._getMarker(ctx.positionMarkers[idx]);
return new Selection(selectionStartMarker.lineNumber, selectionStartMarker.column, positionMarker.lineNumber, positionMarker.column);
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);
}
return new Selection(range.endLineNumber, range.endColumn, range.startLineNumber, range.startColumn);
}
});
} else {
@@ -753,37 +766,31 @@ class CommandExecutor {
};
const trackSelection = (selection: Selection, trackPreviousOnEmpty?: boolean) => {
let selectionMarkerStickToPreviousCharacter: boolean;
let positionMarkerStickToPreviousCharacter: boolean;
let stickiness: editorCommon.TrackedRangeStickiness;
if (selection.isEmpty()) {
// Try to lock it with surrounding text
if (typeof trackPreviousOnEmpty === 'boolean') {
selectionMarkerStickToPreviousCharacter = trackPreviousOnEmpty;
positionMarkerStickToPreviousCharacter = trackPreviousOnEmpty;
if (trackPreviousOnEmpty) {
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
} else {
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
}
} else {
// Try to lock it with surrounding text
const maxLineColumn = ctx.model.getLineMaxColumn(selection.startLineNumber);
if (selection.startColumn === maxLineColumn) {
selectionMarkerStickToPreviousCharacter = true;
positionMarkerStickToPreviousCharacter = true;
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
} else {
selectionMarkerStickToPreviousCharacter = false;
positionMarkerStickToPreviousCharacter = false;
stickiness = editorCommon.TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
}
}
} else {
if (selection.getDirection() === SelectionDirection.LTR) {
selectionMarkerStickToPreviousCharacter = false;
positionMarkerStickToPreviousCharacter = true;
} else {
selectionMarkerStickToPreviousCharacter = true;
positionMarkerStickToPreviousCharacter = false;
}
stickiness = editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
}
const l = ctx.selectionStartMarkers.length;
ctx.selectionStartMarkers[l] = ctx.model._addMarker(0, selection.selectionStartLineNumber, selection.selectionStartColumn, selectionMarkerStickToPreviousCharacter);
ctx.positionMarkers[l] = ctx.model._addMarker(0, selection.positionLineNumber, selection.positionColumn, positionMarkerStickToPreviousCharacter);
const l = ctx.trackedRanges.length;
const id = ctx.model._setTrackedRange(null, selection, stickiness);
ctx.trackedRanges[l] = id;
ctx.trackedRangesDirection[l] = selection.getDirection();
return l.toString();
};