mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 11:08:31 -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));
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { ICommand, TextModelResolvedOptions, IConfiguration, IModel, ScrollType } from 'vs/editor/common/editorCommon';
|
||||
import { ICommand, IConfiguration, ScrollType } from 'vs/editor/common/editorCommon';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { Selection, ISelection } from 'vs/editor/common/core/selection';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
@@ -19,6 +19,7 @@ import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOption
|
||||
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
|
||||
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { VerticalRevealType } from 'vs/editor/common/view/viewEvents';
|
||||
import { TextModelResolvedOptions, ITextModel } from 'vs/editor/common/model';
|
||||
|
||||
export interface IColumnSelectData {
|
||||
toViewLineNumber: number;
|
||||
@@ -289,11 +290,11 @@ export class SingleCursorState {
|
||||
export class CursorContext {
|
||||
_cursorContextBrand: void;
|
||||
|
||||
public readonly model: IModel;
|
||||
public readonly model: ITextModel;
|
||||
public readonly viewModel: IViewModel;
|
||||
public readonly config: CursorConfiguration;
|
||||
|
||||
constructor(configuration: IConfiguration, model: IModel, viewModel: IViewModel) {
|
||||
constructor(configuration: IConfiguration, model: ITextModel, viewModel: IViewModel) {
|
||||
this.model = model;
|
||||
this.viewModel = viewModel;
|
||||
this.config = new CursorConfiguration(
|
||||
@@ -381,50 +382,6 @@ export class CursorState {
|
||||
return states;
|
||||
}
|
||||
|
||||
public static ensureInEditableRange(context: CursorContext, states: CursorState[]): CursorState[] {
|
||||
const model = context.model;
|
||||
if (!model.hasEditableRange()) {
|
||||
return states;
|
||||
}
|
||||
|
||||
const modelEditableRange = model.getEditableRange();
|
||||
const viewEditableRange = context.convertModelRangeToViewRange(modelEditableRange);
|
||||
|
||||
let result: CursorState[] = [];
|
||||
for (let i = 0, len = states.length; i < len; i++) {
|
||||
const state = states[i];
|
||||
|
||||
if (state.modelState) {
|
||||
const newModelState = CursorState._ensureInEditableRange(state.modelState, modelEditableRange);
|
||||
result[i] = newModelState ? CursorState.fromModelState(newModelState) : state;
|
||||
} else {
|
||||
const newViewState = CursorState._ensureInEditableRange(state.viewState, viewEditableRange);
|
||||
result[i] = newViewState ? CursorState.fromViewState(newViewState) : state;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static _ensureInEditableRange(state: SingleCursorState, editableRange: Range): SingleCursorState {
|
||||
const position = state.position;
|
||||
|
||||
if (position.lineNumber < editableRange.startLineNumber || (position.lineNumber === editableRange.startLineNumber && position.column < editableRange.startColumn)) {
|
||||
return new SingleCursorState(
|
||||
state.selectionStart, state.selectionStartLeftoverVisibleColumns,
|
||||
new Position(editableRange.startLineNumber, editableRange.startColumn), 0
|
||||
);
|
||||
}
|
||||
|
||||
if (position.lineNumber > editableRange.endLineNumber || (position.lineNumber === editableRange.endLineNumber && position.column > editableRange.endColumn)) {
|
||||
return new SingleCursorState(
|
||||
state.selectionStart, state.selectionStartLeftoverVisibleColumns,
|
||||
new Position(editableRange.endLineNumber, editableRange.endColumn), 0
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
readonly modelState: SingleCursorState;
|
||||
readonly viewState: SingleCursorState;
|
||||
|
||||
@@ -497,6 +454,8 @@ export class CursorColumns {
|
||||
let charCode = lineContent.charCodeAt(i);
|
||||
if (charCode === CharCode.Tab) {
|
||||
result = this.nextTabStop(result, tabSize);
|
||||
} else if (strings.isFullWidthCharacter(charCode)) {
|
||||
result = result + 2;
|
||||
} else {
|
||||
result = result + 1;
|
||||
}
|
||||
@@ -522,6 +481,8 @@ export class CursorColumns {
|
||||
let afterVisibleColumn: number;
|
||||
if (charCode === CharCode.Tab) {
|
||||
afterVisibleColumn = this.nextTabStop(beforeVisibleColumn, tabSize);
|
||||
} else if (strings.isFullWidthCharacter(charCode)) {
|
||||
afterVisibleColumn = beforeVisibleColumn + 2;
|
||||
} else {
|
||||
afterVisibleColumn = beforeVisibleColumn + 1;
|
||||
}
|
||||
|
||||
@@ -155,22 +155,6 @@ export class CursorMoveCommands {
|
||||
}
|
||||
|
||||
public static selectAll(context: CursorContext, cursor: CursorState): CursorState {
|
||||
|
||||
if (context.model.hasEditableRange()) {
|
||||
// Toggle between selecting editable range and selecting the entire buffer
|
||||
|
||||
const editableRange = context.model.getEditableRange();
|
||||
const selection = cursor.modelState.selection;
|
||||
|
||||
if (!selection.equalsRange(editableRange)) {
|
||||
// Selection is not editable range => select editable range
|
||||
return CursorState.fromModelState(new SingleCursorState(
|
||||
new Range(editableRange.startLineNumber, editableRange.startColumn, editableRange.startLineNumber, editableRange.startColumn), 0,
|
||||
new Position(editableRange.endLineNumber, editableRange.endColumn), 0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
const lineCount = context.model.getLineCount();
|
||||
const maxColumn = context.model.getLineMaxColumn(lineCount);
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ export class MoveOperations {
|
||||
const currentVisibleColumn = CursorColumns.visibleColumnFromColumn(model.getLineContent(lineNumber), column, config.tabSize) + leftoverVisibleColumns;
|
||||
|
||||
lineNumber = lineNumber + count;
|
||||
var lineCount = model.getLineCount();
|
||||
let lineCount = model.getLineCount();
|
||||
if (lineNumber > lineCount) {
|
||||
lineNumber = lineCount;
|
||||
if (allowMoveOnLastLine) {
|
||||
|
||||
@@ -8,7 +8,8 @@ import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { ReplaceCommand, ReplaceCommandWithoutChangingPosition, ReplaceCommandWithOffsetCursorState } from 'vs/editor/common/commands/replaceCommand';
|
||||
import { CursorColumns, CursorConfiguration, ICursorSimpleModel, EditOperationResult, EditOperationType } from 'vs/editor/common/controller/cursorCommon';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { ICommand, ITokenizedModel } from 'vs/editor/common/editorCommon';
|
||||
import { ICommand } from 'vs/editor/common/editorCommon';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { ShiftCommand } from 'vs/editor/common/commands/shiftCommand';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
@@ -109,7 +110,7 @@ export class TypeOperations {
|
||||
});
|
||||
}
|
||||
|
||||
private static _distributePasteToCursors(selections: Selection[], pasteOnNewLine: boolean, text: string): string[] {
|
||||
private static _distributePasteToCursors(selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): string[] {
|
||||
if (pasteOnNewLine) {
|
||||
return null;
|
||||
}
|
||||
@@ -118,22 +119,15 @@ export class TypeOperations {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
if (selections[i].startLineNumber !== selections[i].endLineNumber) {
|
||||
return null;
|
||||
}
|
||||
if (multicursorText && multicursorText.length === selections.length) {
|
||||
return multicursorText;
|
||||
}
|
||||
|
||||
let pastePieces = text.split(/\r\n|\r|\n/);
|
||||
if (pastePieces.length !== selections.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return pastePieces;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static paste(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[], pasteOnNewLine: boolean, text: string): EditOperationResult {
|
||||
const distributedPaste = this._distributePasteToCursors(selections, pasteOnNewLine, text);
|
||||
public static paste(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[], text: string, pasteOnNewLine: boolean, multicursorText: string[]): EditOperationResult {
|
||||
const distributedPaste = this._distributePasteToCursors(selections, text, pasteOnNewLine, multicursorText);
|
||||
|
||||
if (distributedPaste) {
|
||||
selections = selections.sort(Range.compareRangesUsingStarts);
|
||||
@@ -143,7 +137,7 @@ export class TypeOperations {
|
||||
}
|
||||
}
|
||||
|
||||
private static _goodIndentForLine(config: CursorConfiguration, model: ITokenizedModel, lineNumber: number): string {
|
||||
private static _goodIndentForLine(config: CursorConfiguration, model: ITextModel, lineNumber: number): string {
|
||||
let action: IndentAction | EnterAction;
|
||||
let indentation: string;
|
||||
|
||||
@@ -214,7 +208,7 @@ export class TypeOperations {
|
||||
return new ReplaceCommand(selection, typeText, insertsAutoWhitespace);
|
||||
}
|
||||
|
||||
public static tab(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[]): ICommand[] {
|
||||
public static tab(config: CursorConfiguration, model: ITextModel, selections: Selection[]): ICommand[] {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const selection = selections[i];
|
||||
@@ -255,7 +249,7 @@ export class TypeOperations {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static replacePreviousChar(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], txt: string, replaceCharCnt: number): EditOperationResult {
|
||||
public static replacePreviousChar(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], txt: string, replaceCharCnt: number): EditOperationResult {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const selection = selections[i];
|
||||
@@ -285,7 +279,7 @@ export class TypeOperations {
|
||||
}
|
||||
}
|
||||
|
||||
private static _enter(config: CursorConfiguration, model: ITokenizedModel, keepPosition: boolean, range: Range): ICommand {
|
||||
private static _enter(config: CursorConfiguration, model: ITextModel, keepPosition: boolean, range: Range): ICommand {
|
||||
if (!model.isCheapToTokenize(range.getStartPosition().lineNumber)) {
|
||||
let lineText = model.getLineContent(range.startLineNumber);
|
||||
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
|
||||
@@ -382,7 +376,7 @@ export class TypeOperations {
|
||||
}
|
||||
}
|
||||
|
||||
private static _isAutoIndentType(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[]): boolean {
|
||||
private static _isAutoIndentType(config: CursorConfiguration, model: ITextModel, selections: Selection[]): boolean {
|
||||
if (!config.autoIndent) {
|
||||
return false;
|
||||
}
|
||||
@@ -396,7 +390,7 @@ export class TypeOperations {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static _runAutoIndentType(config: CursorConfiguration, model: ITokenizedModel, range: Range, ch: string): ICommand {
|
||||
private static _runAutoIndentType(config: CursorConfiguration, model: ITextModel, range: Range, ch: string): ICommand {
|
||||
let currentIndentation = LanguageConfigurationRegistry.getIndentationAtPosition(model, range.startLineNumber, range.startColumn);
|
||||
let actualIndentation = LanguageConfigurationRegistry.getIndentActionForType(model, range, ch, {
|
||||
shiftIndent: (indentation) => {
|
||||
@@ -432,7 +426,7 @@ export class TypeOperations {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static _isAutoClosingCloseCharType(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): boolean {
|
||||
private static _isAutoClosingCloseCharType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
|
||||
if (!config.autoClosingBrackets || !config.autoClosingPairsClose.hasOwnProperty(ch)) {
|
||||
return false;
|
||||
}
|
||||
@@ -475,7 +469,7 @@ export class TypeOperations {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
private static _runAutoClosingCloseCharType(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
private static _runAutoClosingCloseCharType(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const selection = selections[i];
|
||||
@@ -489,7 +483,7 @@ export class TypeOperations {
|
||||
});
|
||||
}
|
||||
|
||||
private static _isAutoClosingOpenCharType(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): boolean {
|
||||
private static _isAutoClosingOpenCharType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
|
||||
if (!config.autoClosingBrackets || !config.autoClosingPairsOpen.hasOwnProperty(ch)) {
|
||||
return false;
|
||||
}
|
||||
@@ -557,7 +551,7 @@ export class TypeOperations {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static _runAutoClosingOpenCharType(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
private static _runAutoClosingOpenCharType(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const selection = selections[i];
|
||||
@@ -570,7 +564,7 @@ export class TypeOperations {
|
||||
});
|
||||
}
|
||||
|
||||
private static _isSurroundSelectionType(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): boolean {
|
||||
private static _isSurroundSelectionType(config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): boolean {
|
||||
if (!config.autoClosingBrackets || !config.surroundingPairs.hasOwnProperty(ch)) {
|
||||
return false;
|
||||
}
|
||||
@@ -604,7 +598,7 @@ export class TypeOperations {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static _runSurroundSelectionType(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
private static _runSurroundSelectionType(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const selection = selections[i];
|
||||
@@ -617,14 +611,14 @@ export class TypeOperations {
|
||||
});
|
||||
}
|
||||
|
||||
private static _isTypeInterceptorElectricChar(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[]) {
|
||||
private static _isTypeInterceptorElectricChar(config: CursorConfiguration, model: ITextModel, selections: Selection[]) {
|
||||
if (selections.length === 1 && model.isCheapToTokenize(selections[0].getEndPosition().lineNumber)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static _typeInterceptorElectricChar(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selection: Selection, ch: string): EditOperationResult {
|
||||
private static _typeInterceptorElectricChar(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selection: Selection, ch: string): EditOperationResult {
|
||||
if (!config.electricChars.hasOwnProperty(ch) || !selection.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -687,7 +681,7 @@ export class TypeOperations {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static typeWithInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
public static typeWithInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], ch: string): EditOperationResult {
|
||||
|
||||
if (ch === '\n') {
|
||||
let commands: ICommand[] = [];
|
||||
@@ -754,7 +748,7 @@ export class TypeOperations {
|
||||
});
|
||||
}
|
||||
|
||||
public static typeWithoutInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], str: string): EditOperationResult {
|
||||
public static typeWithoutInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITextModel, selections: Selection[], str: string): EditOperationResult {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
commands[i] = new ReplaceCommand(selections[i], str);
|
||||
@@ -765,7 +759,7 @@ export class TypeOperations {
|
||||
});
|
||||
}
|
||||
|
||||
public static lineInsertBefore(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[]): ICommand[] {
|
||||
public static lineInsertBefore(config: CursorConfiguration, model: ITextModel, selections: Selection[]): ICommand[] {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
let lineNumber = selections[i].positionLineNumber;
|
||||
@@ -782,7 +776,7 @@ export class TypeOperations {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static lineInsertAfter(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[]): ICommand[] {
|
||||
public static lineInsertAfter(config: CursorConfiguration, model: ITextModel, selections: Selection[]): ICommand[] {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const lineNumber = selections[i].positionLineNumber;
|
||||
@@ -792,7 +786,7 @@ export class TypeOperations {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static lineBreakInsert(config: CursorConfiguration, model: ITokenizedModel, selections: Selection[]): ICommand[] {
|
||||
public static lineBreakInsert(config: CursorConfiguration, model: ITextModel, selections: Selection[]): ICommand[] {
|
||||
let commands: ICommand[] = [];
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
commands[i] = this._enter(config, model, true, selections[i]);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { SingleCursorState, CursorContext, CursorState } from 'vs/editor/common/
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection, SelectionDirection } from 'vs/editor/common/core/selection';
|
||||
import { TrackedRangeStickiness } from 'vs/editor/common/editorCommon';
|
||||
import { TrackedRangeStickiness } from 'vs/editor/common/model';
|
||||
|
||||
export class OneCursor {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user