未验证 提交 993c1595 编写于 作者: A Alex Dima

Have the Cursor not be a ViewEventEmitter

上级 48dc035b
...@@ -555,7 +555,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -555,7 +555,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
const validatedModelRange = this._modelData.model.validateRange(modelRange); const validatedModelRange = this._modelData.model.validateRange(modelRange);
const viewRange = this._modelData.viewModel.coordinatesConverter.convertModelRangeToViewRange(validatedModelRange); const viewRange = this._modelData.viewModel.coordinatesConverter.convertModelRangeToViewRange(validatedModelRange);
this._modelData.viewModel.cursor.emitCursorRevealRange('api', viewRange, null, verticalType, revealHorizontal, scrollType); this._modelData.viewModel.revealRange('api', revealHorizontal, viewRange, verticalType, scrollType);
} }
public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void { public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
...@@ -1544,7 +1544,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -1544,7 +1544,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
if (this.isSimpleWidget) { if (this.isSimpleWidget) {
commandDelegate = { commandDelegate = {
executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => { executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => {
editorCommand.runCoreEditorCommand(viewModel.getCursors(), args); editorCommand.runCoreEditorCommand(this, viewModel, viewModel.getCursors(), args);
}, },
paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => { paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => {
this._paste('keyboard', text, pasteOnNewLine, multicursorText, mode); this._paste('keyboard', text, pasteOnNewLine, multicursorText, mode);
...@@ -1568,7 +1568,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -1568,7 +1568,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
} else { } else {
commandDelegate = { commandDelegate = {
executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => { executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => {
editorCommand.runCoreEditorCommand(viewModel.getCursors(), args); editorCommand.runCoreEditorCommand(this, viewModel, viewModel.getCursors(), args);
}, },
paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => { paste: (text: string, pasteOnNewLine: boolean, multicursorText: string[] | null, mode: string | null) => {
const payload: editorCommon.PastePayload = { text, pasteOnNewLine, multicursorText, mode }; const payload: editorCommon.PastePayload = { text, pasteOnNewLine, multicursorText, mode };
......
...@@ -7,7 +7,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; ...@@ -7,7 +7,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import * as strings from 'vs/base/common/strings'; import * as strings from 'vs/base/common/strings';
import { CursorCollection } from 'vs/editor/common/controller/cursorCollection'; import { CursorCollection } from 'vs/editor/common/controller/cursorCollection';
import { CursorColumns, CursorConfiguration, CursorContext, CursorState, EditOperationResult, EditOperationType, IColumnSelectData, ICursors, PartialCursorState, RevealTarget, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon'; import { CursorColumns, CursorConfiguration, CursorContext, CursorState, EditOperationResult, EditOperationType, IColumnSelectData, ICursors, PartialCursorState, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon';
import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations'; import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperations';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { TypeOperations, TypeWithAutoClosingCommand } from 'vs/editor/common/controller/cursorTypeOperations'; import { TypeOperations, TypeWithAutoClosingCommand } from 'vs/editor/common/controller/cursorTypeOperations';
...@@ -17,8 +17,8 @@ import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core ...@@ -17,8 +17,8 @@ import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core
import * as editorCommon from 'vs/editor/common/editorCommon'; import * as editorCommon from 'vs/editor/common/editorCommon';
import { ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, ICursorStateComputer, IIdentifiedSingleEditOperation, IValidEditOperation } from 'vs/editor/common/model'; import { ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, ICursorStateComputer, IIdentifiedSingleEditOperation, IValidEditOperation } from 'vs/editor/common/model';
import { RawContentChangedType, ModelRawContentChangedEvent, IModelLanguageChangedEvent } from 'vs/editor/common/model/textModelEvents'; import { RawContentChangedType, ModelRawContentChangedEvent, IModelLanguageChangedEvent } from 'vs/editor/common/model/textModelEvents';
import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewEventsCollector, VerticalRevealType, ViewCursorStateChangedEvent, ViewRevealRangeRequestEvent } from 'vs/editor/common/view/viewEvents';
import { dispose } from 'vs/base/common/lifecycle'; import { dispose, Disposable } from 'vs/base/common/lifecycle';
import { EditorOption, ConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; import { EditorOption, ConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel'; import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
...@@ -162,7 +162,7 @@ class AutoClosedAction { ...@@ -162,7 +162,7 @@ class AutoClosedAction {
} }
} }
export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { export class Cursor extends Disposable implements ICursors {
public static readonly MAX_CURSOR_COUNT = 10000; public static readonly MAX_CURSOR_COUNT = 10000;
...@@ -218,7 +218,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -218,7 +218,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._cursors.updateContext(this.context); this._cursors.updateContext(this.context);
} }
public onLineMappingChanged(): void { public onLineMappingChanged(eventsCollector: ViewEventsCollector): void {
if (this._knownModelVersionId !== this._model.getVersionId()) { if (this._knownModelVersionId !== this._model.getVersionId()) {
// There are model change events that I didn't yet receive. // There are model change events that I didn't yet receive.
// //
...@@ -230,7 +230,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -230,7 +230,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return; return;
} }
// Ensure valid state // Ensure valid state
this.setStates('viewModel', CursorChangeReason.NotSet, this.getAll()); this.setStates(eventsCollector, 'viewModel', CursorChangeReason.NotSet, this.getAll());
} }
public onDidChangeModelLanguage(e: IModelLanguageChangedEvent): void { public onDidChangeModelLanguage(e: IModelLanguageChangedEvent): void {
...@@ -283,7 +283,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -283,7 +283,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return this._cursors.getAll(); return this._cursors.getAll();
} }
public setStates(source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): boolean { public setStates(eventsCollector: ViewEventsCollector, source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): boolean {
let reachedMaxCursorCount = false; let reachedMaxCursorCount = false;
if (states !== null && states.length > Cursor.MAX_CURSOR_COUNT) { if (states !== null && states.length > Cursor.MAX_CURSOR_COUNT) {
states = states.slice(0, Cursor.MAX_CURSOR_COUNT); states = states.slice(0, Cursor.MAX_CURSOR_COUNT);
...@@ -298,19 +298,38 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -298,19 +298,38 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._validateAutoClosedActions(); this._validateAutoClosedActions();
return this._emitStateChangedIfNecessary(source, reason, oldState, reachedMaxCursorCount); return this._emitStateChangedIfNecessary(eventsCollector, source, reason, oldState, reachedMaxCursorCount);
} }
public setColumnSelectData(columnSelectData: IColumnSelectData): void { public setColumnSelectData(columnSelectData: IColumnSelectData): void {
this._columnSelectData = columnSelectData; this._columnSelectData = columnSelectData;
} }
public reveal(source: string | null | undefined, horizontal: boolean, target: RevealTarget, scrollType: editorCommon.ScrollType): void { public revealPrimary(eventsCollector: ViewEventsCollector, source: string | null | undefined, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
this._revealRange(source, target, viewEvents.VerticalRevealType.Simple, horizontal, scrollType); const viewPositions = this._cursors.getViewPositions();
if (viewPositions.length > 1) {
this._emitCursorRevealRange(eventsCollector, source, null, this._cursors.getViewSelections(), VerticalRevealType.Simple, revealHorizontal, scrollType);
return;
} else {
const viewPosition = viewPositions[0];
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column);
this._emitCursorRevealRange(eventsCollector, source, viewRange, null, VerticalRevealType.Simple, revealHorizontal, scrollType);
}
} }
public revealRange(source: string | null | undefined, revealHorizontal: boolean, viewRange: Range, verticalType: viewEvents.VerticalRevealType, scrollType: editorCommon.ScrollType) { private _revealPrimaryCursor(eventsCollector: ViewEventsCollector, source: string | null | undefined, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
this.emitCursorRevealRange(source, viewRange, null, verticalType, revealHorizontal, scrollType); const viewPositions = this._cursors.getViewPositions();
if (viewPositions.length > 1) {
this._emitCursorRevealRange(eventsCollector, source, null, this._cursors.getViewSelections(), verticalType, revealHorizontal, scrollType);
} else {
const viewPosition = viewPositions[0];
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column);
this._emitCursorRevealRange(eventsCollector, source, viewRange, null, verticalType, revealHorizontal, scrollType);
}
}
private _emitCursorRevealRange(eventsCollector: ViewEventsCollector, source: string | null | undefined, viewRange: Range | null, viewSelections: Selection[] | null, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) {
eventsCollector.emit(new ViewRevealRangeRequestEvent(source, viewRange, viewSelections, verticalType, revealHorizontal, scrollType));
} }
public saveState(): editorCommon.ICursorState[] { public saveState(): editorCommon.ICursorState[] {
...@@ -337,7 +356,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -337,7 +356,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return result; return result;
} }
public restoreState(states: editorCommon.ICursorState[]): void { public restoreState(eventsCollector: ViewEventsCollector, states: editorCommon.ICursorState[]): void {
let desiredSelections: ISelection[] = []; let desiredSelections: ISelection[] = [];
...@@ -374,11 +393,11 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -374,11 +393,11 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}); });
} }
this.setStates('restoreState', CursorChangeReason.NotSet, CursorState.fromModelSelections(desiredSelections)); this.setStates(eventsCollector, 'restoreState', CursorChangeReason.NotSet, CursorState.fromModelSelections(desiredSelections));
this.reveal('restoreState', true, RevealTarget.Primary, editorCommon.ScrollType.Immediate); this.revealPrimary(eventsCollector, 'restoreState', true, editorCommon.ScrollType.Immediate);
} }
public onModelContentChanged(e: ModelRawContentChangedEvent): void { public onModelContentChanged(eventsCollector: ViewEventsCollector, e: ModelRawContentChangedEvent): void {
this._knownModelVersionId = e.versionId; this._knownModelVersionId = e.versionId;
if (this._isHandling) { if (this._isHandling) {
...@@ -393,16 +412,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -393,16 +412,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._cursors.dispose(); this._cursors.dispose();
this._cursors = new CursorCollection(this.context); this._cursors = new CursorCollection(this.context);
this._validateAutoClosedActions(); this._validateAutoClosedActions();
this._emitStateChangedIfNecessary('model', CursorChangeReason.ContentFlush, null, false); this._emitStateChangedIfNecessary(eventsCollector, 'model', CursorChangeReason.ContentFlush, null, false);
} else { } else {
if (this._hasFocus && e.resultingSelection && e.resultingSelection.length > 0) { if (this._hasFocus && e.resultingSelection && e.resultingSelection.length > 0) {
const cursorState = CursorState.fromModelSelections(e.resultingSelection); const cursorState = CursorState.fromModelSelections(e.resultingSelection);
if (this.setStates('modelChange', e.isUndoing ? CursorChangeReason.Undo : e.isRedoing ? CursorChangeReason.Redo : CursorChangeReason.RecoverFromMarkers, cursorState)) { if (this.setStates(eventsCollector, 'modelChange', e.isUndoing ? CursorChangeReason.Undo : e.isRedoing ? CursorChangeReason.Redo : CursorChangeReason.RecoverFromMarkers, cursorState)) {
this._revealRange('modelChange', RevealTarget.Primary, viewEvents.VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth); this._revealPrimaryCursor(eventsCollector, 'modelChange', VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth);
} }
} else { } else {
const selectionsFromMarkers = this._cursors.readSelectionFromMarkers(); const selectionsFromMarkers = this._cursors.readSelectionFromMarkers();
this.setStates('modelChange', CursorChangeReason.RecoverFromMarkers, CursorState.fromModelSelections(selectionsFromMarkers)); this.setStates(eventsCollector, 'modelChange', CursorChangeReason.RecoverFromMarkers, CursorState.fromModelSelections(selectionsFromMarkers));
} }
} }
} }
...@@ -411,6 +430,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -411,6 +430,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return this._cursors.getPrimaryCursor().modelState.selection; return this._cursors.getPrimaryCursor().modelState.selection;
} }
public getTopMostViewPosition(): Position {
return this._cursors.getTopMostViewPosition();
}
public getBottomMostViewPosition(): Position {
return this._cursors.getBottomMostViewPosition();
}
public getColumnSelectData(): IColumnSelectData { public getColumnSelectData(): IColumnSelectData {
if (this._columnSelectData) { if (this._columnSelectData) {
return this._columnSelectData; return this._columnSelectData;
...@@ -435,8 +462,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -435,8 +462,8 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return this._cursors.getPrimaryCursor().modelState.position; return this._cursors.getPrimaryCursor().modelState.position;
} }
public setSelections(source: string | null | undefined, selections: readonly ISelection[]): void { public setSelections(eventsCollector: ViewEventsCollector, source: string | null | undefined, selections: readonly ISelection[]): void {
this.setStates(source, CursorChangeReason.NotSet, CursorState.fromModelSelections(selections)); this.setStates(eventsCollector, source, CursorChangeReason.NotSet, CursorState.fromModelSelections(selections));
} }
public getPrevEditOperationType(): EditOperationType { public getPrevEditOperationType(): EditOperationType {
...@@ -527,7 +554,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -527,7 +554,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
// ----------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------
// ----- emitting events // ----- emitting events
private _emitStateChangedIfNecessary(source: string | null | undefined, reason: CursorChangeReason, oldState: CursorModelState | null, reachedMaxCursorCount: boolean): boolean { private _emitStateChangedIfNecessary(eventsCollector: ViewEventsCollector, source: string | null | undefined, reason: CursorChangeReason, oldState: CursorModelState | null, reachedMaxCursorCount: boolean): boolean {
const newState = new CursorModelState(this._model, this); const newState = new CursorModelState(this._model, this);
if (newState.equals(oldState)) { if (newState.equals(oldState)) {
return false; return false;
...@@ -537,7 +564,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -537,7 +564,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
const viewSelections = this._cursors.getViewSelections(); const viewSelections = this._cursors.getViewSelections();
// Let the view get the event first. // Let the view get the event first.
this._emitSingleViewEvent(new viewEvents.ViewCursorStateChangedEvent(viewSelections, selections)); eventsCollector.emit(new ViewCursorStateChangedEvent(viewSelections, selections));
// Only after the view has been notified, let the rest of the world know... // Only after the view has been notified, let the rest of the world know...
if (!oldState if (!oldState
...@@ -552,38 +579,6 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -552,38 +579,6 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return true; return true;
} }
private _revealRange(source: string | null | undefined, revealTarget: RevealTarget, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
const viewPositions = this._cursors.getViewPositions();
let viewPosition = viewPositions[0];
if (revealTarget === RevealTarget.TopMost) {
for (let i = 1; i < viewPositions.length; i++) {
if (viewPositions[i].isBefore(viewPosition)) {
viewPosition = viewPositions[i];
}
}
} else if (revealTarget === RevealTarget.BottomMost) {
for (let i = 1; i < viewPositions.length; i++) {
if (viewPosition.isBeforeOrEqual(viewPositions[i])) {
viewPosition = viewPositions[i];
}
}
} else {
if (viewPositions.length > 1) {
this.emitCursorRevealRange(source, null, this._cursors.getViewSelections(), verticalType, revealHorizontal, scrollType);
return;
}
}
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column);
this.emitCursorRevealRange(source, viewRange, null, verticalType, revealHorizontal, scrollType);
}
public emitCursorRevealRange(source: string | null | undefined, viewRange: Range | null, viewSelections: Selection[] | null, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) {
this._emitSingleViewEvent(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, viewSelections, verticalType, revealHorizontal, scrollType));
}
// ----------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------
// ----- handlers beyond this point // ----- handlers beyond this point
...@@ -623,7 +618,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -623,7 +618,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
return indices; return indices;
} }
public executeEdits(source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): void { public executeEdits(eventsCollector: ViewEventsCollector, source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): void {
let autoClosingIndices: [number, number][] | null = null; let autoClosingIndices: [number, number][] | null = null;
if (source === 'snippet') { if (source === 'snippet') {
autoClosingIndices = this._findAutoClosingPairs(edits); autoClosingIndices = this._findAutoClosingPairs(edits);
...@@ -658,14 +653,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -658,14 +653,14 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
}); });
if (selections) { if (selections) {
this._isHandling = false; this._isHandling = false;
this.setSelections(source, selections); this.setSelections(eventsCollector, source, selections);
} }
if (autoClosedCharactersRanges.length > 0) { if (autoClosedCharactersRanges.length > 0) {
this._pushAutoClosedAction(autoClosedCharactersRanges, autoClosedEnclosingRanges); this._pushAutoClosedAction(autoClosedCharactersRanges, autoClosedEnclosingRanges);
} }
} }
private _executeEdit(callback: () => void, source: string | null | undefined, cursorChangeReason: CursorChangeReason = CursorChangeReason.NotSet): void { private _executeEdit(callback: () => void, eventsCollector: ViewEventsCollector, source: string | null | undefined, cursorChangeReason: CursorChangeReason = CursorChangeReason.NotSet): void {
if (this._configuration.options.get(EditorOption.readOnly)) { if (this._configuration.options.get(EditorOption.readOnly)) {
// we cannot edit when read only... // we cannot edit when read only...
this._onDidAttemptReadOnlyEdit.fire(undefined); this._onDidAttemptReadOnlyEdit.fire(undefined);
...@@ -686,17 +681,17 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -686,17 +681,17 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._isHandling = false; this._isHandling = false;
this._cursors.startTrackingSelections(); this._cursors.startTrackingSelections();
this._validateAutoClosedActions(); this._validateAutoClosedActions();
if (this._emitStateChangedIfNecessary(source, cursorChangeReason, oldState, false)) { if (this._emitStateChangedIfNecessary(eventsCollector, source, cursorChangeReason, oldState, false)) {
this._revealRange(source, RevealTarget.Primary, viewEvents.VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth); this._revealPrimaryCursor(eventsCollector, source, VerticalRevealType.Simple, true, editorCommon.ScrollType.Smooth);
} }
} }
public startComposition(): void { public startComposition(eventsCollector: ViewEventsCollector): void {
this._isDoingComposition = true; this._isDoingComposition = true;
this._selectionsWhenCompositionStarted = this.getSelections().slice(0); this._selectionsWhenCompositionStarted = this.getSelections().slice(0);
} }
public endComposition(source?: string | null | undefined): void { public endComposition(eventsCollector: ViewEventsCollector, source?: string | null | undefined): void {
this._isDoingComposition = false; this._isDoingComposition = false;
this._executeEdit(() => { this._executeEdit(() => {
if (!this._isDoingComposition && source === 'keyboard') { if (!this._isDoingComposition && source === 'keyboard') {
...@@ -705,10 +700,10 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -705,10 +700,10 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
this._executeEditOperation(TypeOperations.compositionEndWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this._selectionsWhenCompositionStarted, this.getSelections(), autoClosedCharacters)); this._executeEditOperation(TypeOperations.compositionEndWithInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this._selectionsWhenCompositionStarted, this.getSelections(), autoClosedCharacters));
this._selectionsWhenCompositionStarted = null; this._selectionsWhenCompositionStarted = null;
} }
}, source); }, eventsCollector, source);
} }
public type(text: string, source?: string | null | undefined): void { public type(eventsCollector: ViewEventsCollector, text: string, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
if (source === 'keyboard') { if (source === 'keyboard') {
// If this event is coming straight from the keyboard, look for electric characters and enter // If this event is coming straight from the keyboard, look for electric characters and enter
...@@ -729,28 +724,28 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -729,28 +724,28 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
} else { } else {
this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text)); this._executeEditOperation(TypeOperations.typeWithoutInterceptors(this._prevEditOperationType, this.context.config, this.context.model, this.getSelections(), text));
} }
}, source); }, eventsCollector, source);
} }
public replacePreviousChar(text: string, replaceCharCnt: number, source?: string | null | undefined): void { public replacePreviousChar(eventsCollector: ViewEventsCollector, text: string, replaceCharCnt: number, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, 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));
}, source); }, eventsCollector, source);
} }
public paste(text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void { public paste(eventsCollector: ViewEventsCollector, text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), text, pasteOnNewLine, multicursorText || [])); this._executeEditOperation(TypeOperations.paste(this.context.config, this.context.model, this.getSelections(), text, pasteOnNewLine, multicursorText || []));
}, source, CursorChangeReason.Paste); }, eventsCollector, source, CursorChangeReason.Paste);
} }
public cut(source?: string | null | undefined): void { public cut(eventsCollector: ViewEventsCollector, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(DeleteOperations.cut(this.context.config, this.context.model, this.getSelections())); this._executeEditOperation(DeleteOperations.cut(this.context.config, this.context.model, this.getSelections()));
}, source); }, eventsCollector, source);
} }
public executeCommand(command: editorCommon.ICommand, source?: string | null | undefined): void { public executeCommand(eventsCollector: ViewEventsCollector, command: editorCommon.ICommand, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._cursors.killSecondaryCursors(); this._cursors.killSecondaryCursors();
...@@ -758,16 +753,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { ...@@ -758,16 +753,16 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
shouldPushStackElementBefore: false, shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false shouldPushStackElementAfter: false
})); }));
}, source); }, eventsCollector, source);
} }
public executeCommands(commands: editorCommon.ICommand[], source?: string | null | undefined): void { public executeCommands(eventsCollector: ViewEventsCollector, commands: editorCommon.ICommand[], source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(new EditOperationResult(EditOperationType.Other, commands, { this._executeEditOperation(new EditOperationResult(EditOperationType.Other, commands, {
shouldPushStackElementBefore: false, shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false shouldPushStackElementAfter: false
})); }));
}, source); }, eventsCollector, source);
} }
} }
......
...@@ -82,6 +82,28 @@ export class CursorCollection { ...@@ -82,6 +82,28 @@ export class CursorCollection {
return result; return result;
} }
public getTopMostViewPosition(): Position {
let result = this.primaryCursor.viewState.position;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
const viewPosition = this.secondaryCursors[i].viewState.position;
if (viewPosition.isBefore(result)) {
result = viewPosition;
}
}
return result;
}
public getBottomMostViewPosition(): Position {
let result = this.primaryCursor.viewState.position;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
const viewPosition = this.secondaryCursors[i].viewState.position;
if (result.isBeforeOrEqual(viewPosition)) {
result = viewPosition;
}
}
return result;
}
public getSelections(): Selection[] { public getSelections(): Selection[] {
let result: Selection[] = []; let result: Selection[] = [];
result[0] = this.primaryCursor.modelState.selection; result[0] = this.primaryCursor.modelState.selection;
......
...@@ -7,17 +7,15 @@ import { CharCode } from 'vs/base/common/charCode'; ...@@ -7,17 +7,15 @@ import { CharCode } from 'vs/base/common/charCode';
import { onUnexpectedError } from 'vs/base/common/errors'; import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings'; import * as strings from 'vs/base/common/strings';
import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, ConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption, EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions'; import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, ConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption, EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range'; import { Range } from 'vs/editor/common/core/range';
import { ISelection, Selection } from 'vs/editor/common/core/selection'; import { ISelection, Selection } from 'vs/editor/common/core/selection';
import { ICommand, IConfiguration, ScrollType } from 'vs/editor/common/editorCommon'; import { ICommand, IConfiguration } from 'vs/editor/common/editorCommon';
import { ITextModel, TextModelResolvedOptions } from 'vs/editor/common/model'; import { ITextModel, TextModelResolvedOptions } from 'vs/editor/common/model';
import { TextModel } from 'vs/editor/common/model/textModel'; import { TextModel } from 'vs/editor/common/model/textModel';
import { LanguageIdentifier } from 'vs/editor/common/modes'; import { LanguageIdentifier } from 'vs/editor/common/modes';
import { IAutoClosingPair, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration'; import { IAutoClosingPair, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry'; import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { VerticalRevealType } from 'vs/editor/common/view/viewEvents';
import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel'; import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
import { Constants } from 'vs/base/common/uint'; import { Constants } from 'vs/base/common/uint';
...@@ -55,10 +53,6 @@ export interface ICursors { ...@@ -55,10 +53,6 @@ export interface ICursors {
getColumnSelectData(): IColumnSelectData; getColumnSelectData(): IColumnSelectData;
setColumnSelectData(columnSelectData: IColumnSelectData): void; setColumnSelectData(columnSelectData: IColumnSelectData): void;
setStates(source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): void;
reveal(source: string | null | undefined, horizontal: boolean, target: RevealTarget, scrollType: ScrollType): void;
revealRange(source: string | null | undefined, revealHorizontal: boolean, viewRange: Range, verticalType: VerticalRevealType, scrollType: ScrollType): void;
getPrevEditOperationType(): EditOperationType; getPrevEditOperationType(): EditOperationType;
setPrevEditOperationType(type: EditOperationType): void; setPrevEditOperationType(type: EditOperationType): void;
} }
......
...@@ -10,11 +10,12 @@ import { IPosition, Position } from 'vs/editor/common/core/position'; ...@@ -10,11 +10,12 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range'; import { IRange, Range } from 'vs/editor/common/core/range';
import { INewScrollPosition, ScrollType } from 'vs/editor/common/editorCommon'; import { INewScrollPosition, ScrollType } from 'vs/editor/common/editorCommon';
import { EndOfLinePreference, IActiveIndentGuideInfo, IModelDecorationOptions, TextModelResolvedOptions } from 'vs/editor/common/model'; import { EndOfLinePreference, IActiveIndentGuideInfo, IModelDecorationOptions, TextModelResolvedOptions } from 'vs/editor/common/model';
import { IViewEventEmitter } from 'vs/editor/common/view/viewEvents'; import { IViewEventEmitter, VerticalRevealType } from 'vs/editor/common/view/viewEvents';
import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
import { IEditorWhitespace, IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout'; import { IEditorWhitespace, IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout';
import { EditorTheme } from 'vs/editor/common/view/viewContext'; import { EditorTheme } from 'vs/editor/common/view/viewContext';
import { ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon'; import { ICursorSimpleModel, PartialCursorState } from 'vs/editor/common/controller/cursorCommon';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
export interface IViewWhitespaceViewportData { export interface IViewWhitespaceViewportData {
readonly id: string; readonly id: string;
...@@ -137,6 +138,16 @@ export interface IViewModel extends IViewEventEmitter, ICursorSimpleModel { ...@@ -137,6 +138,16 @@ export interface IViewModel extends IViewEventEmitter, ICursorSimpleModel {
getEOL(): string; getEOL(): string;
getPlainTextToCopy(modelRanges: Range[], emptySelectionClipboard: boolean, forceCRLF: boolean): string | string[]; getPlainTextToCopy(modelRanges: Range[], emptySelectionClipboard: boolean, forceCRLF: boolean): string | string[];
getRichTextToCopy(modelRanges: Range[], emptySelectionClipboard: boolean): { html: string, mode: string } | null; getRichTextToCopy(modelRanges: Range[], emptySelectionClipboard: boolean): { html: string, mode: string } | null;
//#region cursor
setCursorStates(source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): void;
revealPrimary(source: string | null | undefined, revealHorizontal: boolean): void;
revealTopMostCursor(source: string | null | undefined): void;
revealBottomMostCursor(source: string | null | undefined): void;
revealRange(source: string | null | undefined, revealHorizontal: boolean, viewRange: Range, verticalType: VerticalRevealType, scrollType: ScrollType): void;
//#endregion
} }
export class MinimapLinesRenderingData { export class MinimapLinesRenderingData {
......
...@@ -26,7 +26,8 @@ import { RunOnceScheduler } from 'vs/base/common/async'; ...@@ -26,7 +26,8 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import * as platform from 'vs/base/common/platform'; import * as platform from 'vs/base/common/platform';
import { EditorTheme } from 'vs/editor/common/view/viewContext'; import { EditorTheme } from 'vs/editor/common/view/viewContext';
import { Cursor } from 'vs/editor/common/controller/cursor'; import { Cursor } from 'vs/editor/common/controller/cursor';
import { ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursors, PartialCursorState } from 'vs/editor/common/controller/cursorCommon';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
const USE_IDENTITY_LINES_COLLECTION = true; const USE_IDENTITY_LINES_COLLECTION = true;
...@@ -93,16 +94,6 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -93,16 +94,6 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
this.coordinatesConverter = this.lines.createCoordinatesConverter(); this.coordinatesConverter = this.lines.createCoordinatesConverter();
this.cursor = this._register(new Cursor(this.configuration, model, this, this.coordinatesConverter)); this.cursor = this._register(new Cursor(this.configuration, model, this, this.coordinatesConverter));
this._register(this.cursor.addViewEventListener((events) => {
try {
const eventsCollector = this._beginEmitViewEvents();
for (const event of events) {
eventsCollector.emit(event);
}
} finally {
this._endEmitViewEvents();
}
}));
this.viewLayout = this._register(new ViewLayout(this.configuration, this.getLineCount(), scheduleAtNextAnimationFrame)); this.viewLayout = this._register(new ViewLayout(this.configuration, this.getLineCount(), scheduleAtNextAnimationFrame));
...@@ -183,7 +174,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -183,7 +174,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emit(new viewEvents.ViewFlushedEvent());
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount()); this.viewLayout.onFlushed(this.getLineCount());
...@@ -307,7 +298,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -307,7 +298,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
if (!hadOtherModelChange && hadModelLineChangeThatChangedLineMapping) { if (!hadOtherModelChange && hadModelLineChangeThatChangedLineMapping) {
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
} }
} finally { } finally {
...@@ -329,7 +320,12 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -329,7 +320,12 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
} }
} }
this.cursor.onModelContentChanged(e); try {
const eventsCollector = this._beginEmitViewEvents();
this.cursor.onModelContentChanged(eventsCollector, e);
} finally {
this._endEmitViewEvents();
}
})); }));
this._register(this.model.onDidChangeTokens((e) => { this._register(this.model.onDidChangeTokens((e) => {
...@@ -362,14 +358,14 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -362,14 +358,14 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
this._register(this.model.onDidChangeOptions((e) => { this._register(this.model.onDidChangeOptions((e) => {
// A tab size change causes a line mapping changed event => all view parts will repaint OK, no further event needed here // A tab size change causes a line mapping changed event => all view parts will repaint OK, no further event needed here
if (this.lines.setTabSize(this.model.getOptions().tabSize)) { if (this.lines.setTabSize(this.model.getOptions().tabSize)) {
this.cursor.onLineMappingChanged();
this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount());
try { try {
const eventsCollector = this._beginEmitViewEvents(); const eventsCollector = this._beginEmitViewEvents();
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emit(new viewEvents.ViewFlushedEvent());
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount());
} finally { } finally {
this._endEmitViewEvents(); this._endEmitViewEvents();
} }
...@@ -393,7 +389,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -393,7 +389,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emit(new viewEvents.ViewFlushedEvent());
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount()); this.viewLayout.onFlushed(this.getLineCount());
this.viewLayout.onHeightMaybeChanged(); this.viewLayout.onHeightMaybeChanged();
...@@ -845,42 +841,70 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel ...@@ -845,42 +841,70 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
return this.cursor.getPrimaryCursor().modelState.position; return this.cursor.getPrimaryCursor().modelState.position;
} }
public setSelections(source: string | null | undefined, selections: readonly ISelection[]): void { public setSelections(source: string | null | undefined, selections: readonly ISelection[]): void {
this.cursor.setSelections(source, selections); this._withViewEventsCollector(eventsCollector => this.cursor.setSelections(eventsCollector, source, selections));
}
public setCursorStates(source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): void {
this._withViewEventsCollector(eventsCollector => this.cursor.setStates(eventsCollector, source, reason, states));
} }
public saveCursorState(): ICursorState[] { public saveCursorState(): ICursorState[] {
return this.cursor.saveState(); return this.cursor.saveState();
} }
public restoreCursorState(states: ICursorState[]): void { public restoreCursorState(states: ICursorState[]): void {
this.cursor.restoreState(states); this._withViewEventsCollector(eventsCollector => this.cursor.restoreState(eventsCollector, states));
} }
public executeEdits(source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): void { public executeEdits(source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): void {
this.cursor.executeEdits(source, edits, cursorStateComputer); this._withViewEventsCollector(eventsCollector => this.cursor.executeEdits(eventsCollector, source, edits, cursorStateComputer));
} }
public startComposition(): void { public startComposition(): void {
this.cursor.startComposition(); this._withViewEventsCollector(eventsCollector => this.cursor.startComposition(eventsCollector));
} }
public endComposition(source?: string | null | undefined): void { public endComposition(source?: string | null | undefined): void {
this.cursor.endComposition(source); this._withViewEventsCollector(eventsCollector => this.cursor.endComposition(eventsCollector, source));
} }
public type(text: string, source?: string | null | undefined): void { public type(text: string, source?: string | null | undefined): void {
this.cursor.type(text, source); this._withViewEventsCollector(eventsCollector => this.cursor.type(eventsCollector, text, source));
} }
public replacePreviousChar(text: string, replaceCharCnt: number, source?: string | null | undefined): void { public replacePreviousChar(text: string, replaceCharCnt: number, source?: string | null | undefined): void {
this.cursor.replacePreviousChar(text, replaceCharCnt, source); this._withViewEventsCollector(eventsCollector => this.cursor.replacePreviousChar(eventsCollector, text, replaceCharCnt, source));
} }
public paste(text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void { public paste(text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void {
this.cursor.paste(text, pasteOnNewLine, multicursorText, source); this._withViewEventsCollector(eventsCollector => this.cursor.paste(eventsCollector, text, pasteOnNewLine, multicursorText, source));
} }
public cut(source?: string | null | undefined): void { public cut(source?: string | null | undefined): void {
this.cursor.cut(source); this._withViewEventsCollector(eventsCollector => this.cursor.cut(eventsCollector, source));
} }
public executeCommand(command: ICommand, source?: string | null | undefined): void { public executeCommand(command: ICommand, source?: string | null | undefined): void {
this.cursor.executeCommand(command, source); this._withViewEventsCollector(eventsCollector => this.cursor.executeCommand(eventsCollector, command, source));
} }
public executeCommands(commands: ICommand[], source?: string | null | undefined): void { public executeCommands(commands: ICommand[], source?: string | null | undefined): void {
this.cursor.executeCommands(commands, source); this._withViewEventsCollector(eventsCollector => this.cursor.executeCommands(eventsCollector, commands, source));
}
public revealPrimary(source: string | null | undefined, revealHorizontal: boolean): void {
this._withViewEventsCollector(eventsCollector => this.cursor.revealPrimary(eventsCollector, source, revealHorizontal, ScrollType.Smooth));
}
public revealTopMostCursor(source: string | null | undefined): void {
const viewPosition = this.cursor.getTopMostViewPosition();
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column);
this._withViewEventsCollector(eventsCollector => eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, null, viewEvents.VerticalRevealType.Simple, true, ScrollType.Smooth)));
}
public revealBottomMostCursor(source: string | null | undefined): void {
const viewPosition = this.cursor.getBottomMostViewPosition();
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column);
this._withViewEventsCollector(eventsCollector => eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, null, viewEvents.VerticalRevealType.Simple, true, ScrollType.Smooth)));
}
public revealRange(source: string | null | undefined, revealHorizontal: boolean, viewRange: Range, verticalType: viewEvents.VerticalRevealType, scrollType: ScrollType): void {
this._withViewEventsCollector(eventsCollector => eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, null, verticalType, revealHorizontal, scrollType)));
} }
//#endregion //#endregion
private _withViewEventsCollector(callback: (eventsCollector: viewEvents.ViewEventsCollector) => void): void {
try {
const eventsCollector = this._beginEmitViewEvents();
callback(eventsCollector);
} finally {
this._endEmitViewEvents();
}
}
} }
...@@ -9,7 +9,6 @@ import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes'; ...@@ -9,7 +9,6 @@ import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { RevealTarget } from 'vs/editor/common/controller/cursorCommon';
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { CursorMoveCommands } from 'vs/editor/common/controller/cursorMoveCommands'; import { CursorMoveCommands } from 'vs/editor/common/controller/cursorMoveCommands';
import { Range } from 'vs/editor/common/core/range'; import { Range } from 'vs/editor/common/core/range';
...@@ -61,6 +60,7 @@ export class InsertCursorAbove extends EditorAction { ...@@ -61,6 +60,7 @@ export class InsertCursorAbove extends EditorAction {
} }
const useLogicalLine = (args && args.logicalLine === true); const useLogicalLine = (args && args.logicalLine === true);
const viewModel = editor._getViewModel();
const cursors = editor._getCursors(); const cursors = editor._getCursors();
const context = cursors.context; const context = cursors.context;
...@@ -69,12 +69,12 @@ export class InsertCursorAbove extends EditorAction { ...@@ -69,12 +69,12 @@ export class InsertCursorAbove extends EditorAction {
} }
context.model.pushStackElement(); context.model.pushStackElement();
cursors.setStates( viewModel.setCursorStates(
args.source, args.source,
CursorChangeReason.Explicit, CursorChangeReason.Explicit,
CursorMoveCommands.addCursorUp(context, cursors.getAll(), useLogicalLine) CursorMoveCommands.addCursorUp(context, cursors.getAll(), useLogicalLine)
); );
cursors.reveal(args.source, true, RevealTarget.TopMost, ScrollType.Smooth); viewModel.revealTopMostCursor(args.source);
} }
} }
...@@ -110,6 +110,7 @@ export class InsertCursorBelow extends EditorAction { ...@@ -110,6 +110,7 @@ export class InsertCursorBelow extends EditorAction {
} }
const useLogicalLine = (args && args.logicalLine === true); const useLogicalLine = (args && args.logicalLine === true);
const viewModel = editor._getViewModel();
const cursors = editor._getCursors(); const cursors = editor._getCursors();
const context = cursors.context; const context = cursors.context;
...@@ -118,12 +119,12 @@ export class InsertCursorBelow extends EditorAction { ...@@ -118,12 +119,12 @@ export class InsertCursorBelow extends EditorAction {
} }
context.model.pushStackElement(); context.model.pushStackElement();
cursors.setStates( viewModel.setCursorStates(
args.source, args.source,
CursorChangeReason.Explicit, CursorChangeReason.Explicit,
CursorMoveCommands.addCursorDown(context, cursors.getAll(), useLogicalLine) CursorMoveCommands.addCursorDown(context, cursors.getAll(), useLogicalLine)
); );
cursors.reveal(args.source, true, RevealTarget.BottomMost, ScrollType.Smooth); viewModel.revealBottomMostCursor(args.source);
} }
} }
......
...@@ -53,7 +53,7 @@ export abstract class MoveWordCommand extends EditorCommand { ...@@ -53,7 +53,7 @@ export abstract class MoveWordCommand extends EditorCommand {
}); });
model.pushStackElement(); model.pushStackElement();
editor._getCursors().setStates('moveWordCommand', CursorChangeReason.NotSet, result.map(r => CursorState.fromModelSelection(r))); editor._getViewModel().setCursorStates('moveWordCommand', CursorChangeReason.NotSet, result.map(r => CursorState.fromModelSelection(r)));
if (result.length === 1) { if (result.length === 1) {
const pos = new Position(result[0].positionLineNumber, result[0].positionColumn); const pos = new Position(result[0].positionLineNumber, result[0].positionColumn);
editor.revealPosition(pos, ScrollType.Smooth); editor.revealPosition(pos, ScrollType.Smooth);
......
...@@ -30,7 +30,7 @@ suite('Cursor move command test', () => { ...@@ -30,7 +30,7 @@ suite('Cursor move command test', () => {
test('move left should move to left character', () => { test('move left should move to left character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveLeft(editor, viewModel); moveLeft(editor, viewModel);
cursorEqual(viewModel, 1, 7); cursorEqual(viewModel, 1, 7);
}); });
...@@ -38,7 +38,7 @@ suite('Cursor move command test', () => { ...@@ -38,7 +38,7 @@ suite('Cursor move command test', () => {
test('move left should move to left by n characters', () => { test('move left should move to left by n characters', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveLeft(editor, viewModel, 3); moveLeft(editor, viewModel, 3);
cursorEqual(viewModel, 1, 5); cursorEqual(viewModel, 1, 5);
}); });
...@@ -46,7 +46,7 @@ suite('Cursor move command test', () => { ...@@ -46,7 +46,7 @@ suite('Cursor move command test', () => {
test('move left should move to left by half line', () => { test('move left should move to left by half line', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveLeft(editor, viewModel, 1, CursorMove.RawUnit.HalfLine); moveLeft(editor, viewModel, 1, CursorMove.RawUnit.HalfLine);
cursorEqual(viewModel, 1, 1); cursorEqual(viewModel, 1, 1);
}); });
...@@ -54,7 +54,7 @@ suite('Cursor move command test', () => { ...@@ -54,7 +54,7 @@ suite('Cursor move command test', () => {
test('move left moves to previous line', () => { test('move left moves to previous line', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 2, 3); moveTo(editor, viewModel, 2, 3);
moveLeft(editor, viewModel, 10); moveLeft(editor, viewModel, 10);
cursorEqual(viewModel, 1, 21); cursorEqual(viewModel, 1, 21);
}); });
...@@ -62,7 +62,7 @@ suite('Cursor move command test', () => { ...@@ -62,7 +62,7 @@ suite('Cursor move command test', () => {
test('move right should move to right character', () => { test('move right should move to right character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 5); moveTo(editor, viewModel, 1, 5);
moveRight(editor, viewModel); moveRight(editor, viewModel);
cursorEqual(viewModel, 1, 6); cursorEqual(viewModel, 1, 6);
}); });
...@@ -70,7 +70,7 @@ suite('Cursor move command test', () => { ...@@ -70,7 +70,7 @@ suite('Cursor move command test', () => {
test('move right should move to right by n characters', () => { test('move right should move to right by n characters', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 2); moveTo(editor, viewModel, 1, 2);
moveRight(editor, viewModel, 6); moveRight(editor, viewModel, 6);
cursorEqual(viewModel, 1, 8); cursorEqual(viewModel, 1, 8);
}); });
...@@ -78,7 +78,7 @@ suite('Cursor move command test', () => { ...@@ -78,7 +78,7 @@ suite('Cursor move command test', () => {
test('move right should move to right by half line', () => { test('move right should move to right by half line', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 4); moveTo(editor, viewModel, 1, 4);
moveRight(editor, viewModel, 1, CursorMove.RawUnit.HalfLine); moveRight(editor, viewModel, 1, CursorMove.RawUnit.HalfLine);
cursorEqual(viewModel, 1, 14); cursorEqual(viewModel, 1, 14);
}); });
...@@ -86,7 +86,7 @@ suite('Cursor move command test', () => { ...@@ -86,7 +86,7 @@ suite('Cursor move command test', () => {
test('move right moves to next line', () => { test('move right moves to next line', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveRight(editor, viewModel, 100); moveRight(editor, viewModel, 100);
cursorEqual(viewModel, 2, 1); cursorEqual(viewModel, 2, 1);
}); });
...@@ -94,7 +94,7 @@ suite('Cursor move command test', () => { ...@@ -94,7 +94,7 @@ suite('Cursor move command test', () => {
test('move to first character of line from middle', () => { test('move to first character of line from middle', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveToLineStart(editor, viewModel); moveToLineStart(editor, viewModel);
cursorEqual(viewModel, 1, 1); cursorEqual(viewModel, 1, 1);
}); });
...@@ -102,7 +102,7 @@ suite('Cursor move command test', () => { ...@@ -102,7 +102,7 @@ suite('Cursor move command test', () => {
test('move to first character of line from first non white space character', () => { test('move to first character of line from first non white space character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 6); moveTo(editor, viewModel, 1, 6);
moveToLineStart(editor, viewModel); moveToLineStart(editor, viewModel);
cursorEqual(viewModel, 1, 1); cursorEqual(viewModel, 1, 1);
}); });
...@@ -110,7 +110,7 @@ suite('Cursor move command test', () => { ...@@ -110,7 +110,7 @@ suite('Cursor move command test', () => {
test('move to first character of line from first character', () => { test('move to first character of line from first character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 1); moveTo(editor, viewModel, 1, 1);
moveToLineStart(editor, viewModel); moveToLineStart(editor, viewModel);
cursorEqual(viewModel, 1, 1); cursorEqual(viewModel, 1, 1);
}); });
...@@ -118,7 +118,7 @@ suite('Cursor move command test', () => { ...@@ -118,7 +118,7 @@ suite('Cursor move command test', () => {
test('move to first non white space character of line from middle', () => { test('move to first non white space character of line from middle', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveToLineFirstNonWhitespaceCharacter(editor, viewModel); moveToLineFirstNonWhitespaceCharacter(editor, viewModel);
cursorEqual(viewModel, 1, 6); cursorEqual(viewModel, 1, 6);
}); });
...@@ -126,7 +126,7 @@ suite('Cursor move command test', () => { ...@@ -126,7 +126,7 @@ suite('Cursor move command test', () => {
test('move to first non white space character of line from first non white space character', () => { test('move to first non white space character of line from first non white space character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 6); moveTo(editor, viewModel, 1, 6);
moveToLineFirstNonWhitespaceCharacter(editor, viewModel); moveToLineFirstNonWhitespaceCharacter(editor, viewModel);
cursorEqual(viewModel, 1, 6); cursorEqual(viewModel, 1, 6);
}); });
...@@ -134,7 +134,7 @@ suite('Cursor move command test', () => { ...@@ -134,7 +134,7 @@ suite('Cursor move command test', () => {
test('move to first non white space character of line from first character', () => { test('move to first non white space character of line from first character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 1); moveTo(editor, viewModel, 1, 1);
moveToLineFirstNonWhitespaceCharacter(editor, viewModel); moveToLineFirstNonWhitespaceCharacter(editor, viewModel);
cursorEqual(viewModel, 1, 6); cursorEqual(viewModel, 1, 6);
}); });
...@@ -142,7 +142,7 @@ suite('Cursor move command test', () => { ...@@ -142,7 +142,7 @@ suite('Cursor move command test', () => {
test('move to end of line from middle', () => { test('move to end of line from middle', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveToLineEnd(editor, viewModel); moveToLineEnd(editor, viewModel);
cursorEqual(viewModel, 1, 21); cursorEqual(viewModel, 1, 21);
}); });
...@@ -150,7 +150,7 @@ suite('Cursor move command test', () => { ...@@ -150,7 +150,7 @@ suite('Cursor move command test', () => {
test('move to end of line from last non white space character', () => { test('move to end of line from last non white space character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 19); moveTo(editor, viewModel, 1, 19);
moveToLineEnd(editor, viewModel); moveToLineEnd(editor, viewModel);
cursorEqual(viewModel, 1, 21); cursorEqual(viewModel, 1, 21);
}); });
...@@ -158,7 +158,7 @@ suite('Cursor move command test', () => { ...@@ -158,7 +158,7 @@ suite('Cursor move command test', () => {
test('move to end of line from line end', () => { test('move to end of line from line end', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 21); moveTo(editor, viewModel, 1, 21);
moveToLineEnd(editor, viewModel); moveToLineEnd(editor, viewModel);
cursorEqual(viewModel, 1, 21); cursorEqual(viewModel, 1, 21);
}); });
...@@ -166,7 +166,7 @@ suite('Cursor move command test', () => { ...@@ -166,7 +166,7 @@ suite('Cursor move command test', () => {
test('move to last non white space character from middle', () => { test('move to last non white space character from middle', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveToLineLastNonWhitespaceCharacter(editor, viewModel); moveToLineLastNonWhitespaceCharacter(editor, viewModel);
cursorEqual(viewModel, 1, 19); cursorEqual(viewModel, 1, 19);
}); });
...@@ -174,7 +174,7 @@ suite('Cursor move command test', () => { ...@@ -174,7 +174,7 @@ suite('Cursor move command test', () => {
test('move to last non white space character from last non white space character', () => { test('move to last non white space character from last non white space character', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 19); moveTo(editor, viewModel, 1, 19);
moveToLineLastNonWhitespaceCharacter(editor, viewModel); moveToLineLastNonWhitespaceCharacter(editor, viewModel);
cursorEqual(viewModel, 1, 19); cursorEqual(viewModel, 1, 19);
}); });
...@@ -182,7 +182,7 @@ suite('Cursor move command test', () => { ...@@ -182,7 +182,7 @@ suite('Cursor move command test', () => {
test('move to last non white space character from line end', () => { test('move to last non white space character from line end', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 21); moveTo(editor, viewModel, 1, 21);
moveToLineLastNonWhitespaceCharacter(editor, viewModel); moveToLineLastNonWhitespaceCharacter(editor, viewModel);
cursorEqual(viewModel, 1, 19); cursorEqual(viewModel, 1, 19);
}); });
...@@ -190,7 +190,7 @@ suite('Cursor move command test', () => { ...@@ -190,7 +190,7 @@ suite('Cursor move command test', () => {
test('move to center of line not from center', () => { test('move to center of line not from center', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 8); moveTo(editor, viewModel, 1, 8);
moveToLineCenter(editor, viewModel); moveToLineCenter(editor, viewModel);
cursorEqual(viewModel, 1, 11); cursorEqual(viewModel, 1, 11);
}); });
...@@ -198,7 +198,7 @@ suite('Cursor move command test', () => { ...@@ -198,7 +198,7 @@ suite('Cursor move command test', () => {
test('move to center of line from center', () => { test('move to center of line from center', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 11); moveTo(editor, viewModel, 1, 11);
moveToLineCenter(editor, viewModel); moveToLineCenter(editor, viewModel);
cursorEqual(viewModel, 1, 11); cursorEqual(viewModel, 1, 11);
}); });
...@@ -222,7 +222,7 @@ suite('Cursor move command test', () => { ...@@ -222,7 +222,7 @@ suite('Cursor move command test', () => {
test('move up by cursor move command', () => { test('move up by cursor move command', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 3, 5); moveTo(editor, viewModel, 3, 5);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
moveUp(editor, viewModel, 2); moveUp(editor, viewModel, 2);
...@@ -235,7 +235,7 @@ suite('Cursor move command test', () => { ...@@ -235,7 +235,7 @@ suite('Cursor move command test', () => {
test('move up by model line cursor move command', () => { test('move up by model line cursor move command', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 3, 5); moveTo(editor, viewModel, 3, 5);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
moveUpByModelLine(editor, viewModel, 2); moveUpByModelLine(editor, viewModel, 2);
...@@ -248,7 +248,7 @@ suite('Cursor move command test', () => { ...@@ -248,7 +248,7 @@ suite('Cursor move command test', () => {
test('move down by model line cursor move command', () => { test('move down by model line cursor move command', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 3, 5); moveTo(editor, viewModel, 3, 5);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
moveDownByModelLine(editor, viewModel, 2); moveDownByModelLine(editor, viewModel, 2);
...@@ -261,7 +261,7 @@ suite('Cursor move command test', () => { ...@@ -261,7 +261,7 @@ suite('Cursor move command test', () => {
test('move up with selection by cursor move command', () => { test('move up with selection by cursor move command', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 3, 5); moveTo(editor, viewModel, 3, 5);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
moveUp(editor, viewModel, 1, true); moveUp(editor, viewModel, 1, true);
...@@ -274,7 +274,7 @@ suite('Cursor move command test', () => { ...@@ -274,7 +274,7 @@ suite('Cursor move command test', () => {
test('move up and down with tabs by cursor move command', () => { test('move up and down with tabs by cursor move command', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveTo(viewModel, 1, 5); moveTo(editor, viewModel, 1, 5);
cursorEqual(viewModel, 1, 5); cursorEqual(viewModel, 1, 5);
moveDown(editor, viewModel, 4); moveDown(editor, viewModel, 4);
...@@ -296,10 +296,10 @@ suite('Cursor move command test', () => { ...@@ -296,10 +296,10 @@ suite('Cursor move command test', () => {
test('move up and down with end of lines starting from a long one by cursor move command', () => { test('move up and down with end of lines starting from a long one by cursor move command', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
moveToEndOfLine(viewModel); moveToEndOfLine(editor, viewModel);
cursorEqual(viewModel, 1, 21); cursorEqual(viewModel, 1, 21);
moveToEndOfLine(viewModel); moveToEndOfLine(editor, viewModel);
cursorEqual(viewModel, 1, 21); cursorEqual(viewModel, 1, 21);
moveDown(editor, viewModel, 2); moveDown(editor, viewModel, 2);
...@@ -320,7 +320,7 @@ suite('Cursor move command test', () => { ...@@ -320,7 +320,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1);
moveTo(viewModel, 2, 2); moveTo(editor, viewModel, 2, 2);
moveToTop(editor, viewModel); moveToTop(editor, viewModel);
cursorEqual(viewModel, 1, 6); cursorEqual(viewModel, 1, 6);
...@@ -331,7 +331,7 @@ suite('Cursor move command test', () => { ...@@ -331,7 +331,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 10, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 10, 1);
moveTo(viewModel, 4, 1); moveTo(editor, viewModel, 4, 1);
moveToTop(editor, viewModel); moveToTop(editor, viewModel);
cursorEqual(viewModel, 2, 2); cursorEqual(viewModel, 2, 2);
...@@ -342,7 +342,7 @@ suite('Cursor move command test', () => { ...@@ -342,7 +342,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 10, 1);
moveTo(viewModel, 4, 1); moveTo(editor, viewModel, 4, 1);
moveToTop(editor, viewModel, 3); moveToTop(editor, viewModel, 3);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
...@@ -353,7 +353,7 @@ suite('Cursor move command test', () => { ...@@ -353,7 +353,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 3, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 3, 1);
moveTo(viewModel, 2, 2); moveTo(editor, viewModel, 2, 2);
moveToTop(editor, viewModel, 4); moveToTop(editor, viewModel, 4);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
...@@ -364,7 +364,7 @@ suite('Cursor move command test', () => { ...@@ -364,7 +364,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(3, 1, 3, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(3, 1, 3, 1);
moveTo(viewModel, 2, 2); moveTo(editor, viewModel, 2, 2);
moveToCenter(editor, viewModel); moveToCenter(editor, viewModel);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
...@@ -375,7 +375,7 @@ suite('Cursor move command test', () => { ...@@ -375,7 +375,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1);
moveTo(viewModel, 2, 2); moveTo(editor, viewModel, 2, 2);
moveToBottom(editor, viewModel); moveToBottom(editor, viewModel);
cursorEqual(viewModel, 5, 1); cursorEqual(viewModel, 5, 1);
...@@ -386,7 +386,7 @@ suite('Cursor move command test', () => { ...@@ -386,7 +386,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 3, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 3, 1);
moveTo(viewModel, 2, 2); moveTo(editor, viewModel, 2, 2);
moveToBottom(editor, viewModel); moveToBottom(editor, viewModel);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
...@@ -397,7 +397,7 @@ suite('Cursor move command test', () => { ...@@ -397,7 +397,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(1, 1, 5, 1);
moveTo(viewModel, 4, 1); moveTo(editor, viewModel, 4, 1);
moveToBottom(editor, viewModel, 3); moveToBottom(editor, viewModel, 3);
cursorEqual(viewModel, 3, 5); cursorEqual(viewModel, 3, 5);
...@@ -408,7 +408,7 @@ suite('Cursor move command test', () => { ...@@ -408,7 +408,7 @@ suite('Cursor move command test', () => {
executeTest((editor, viewModel) => { executeTest((editor, viewModel) => {
viewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 5, 1); viewModel.getCompletelyVisibleViewRange = () => new Range(2, 1, 5, 1);
moveTo(viewModel, 4, 1); moveTo(editor, viewModel, 4, 1);
moveToBottom(editor, viewModel, 5); moveToBottom(editor, viewModel, 5);
cursorEqual(viewModel, 2, 2); cursorEqual(viewModel, 2, 2);
...@@ -501,22 +501,22 @@ function selectionEqual(selection: Selection, posLineNumber: number, posColumn: ...@@ -501,22 +501,22 @@ function selectionEqual(selection: Selection, posLineNumber: number, posColumn:
}, 'selection equal'); }, 'selection equal');
} }
function moveTo(viewModel: ViewModel, lineNumber: number, column: number, inSelectionMode: boolean = false) { function moveTo(editor: ITestCodeEditor, viewModel: ViewModel, lineNumber: number, column: number, inSelectionMode: boolean = false) {
if (inSelectionMode) { if (inSelectionMode) {
CoreNavigationCommands.MoveToSelect.runCoreEditorCommand(viewModel.getCursors(), { CoreNavigationCommands.MoveToSelect.runCoreEditorCommand(editor, viewModel, viewModel.getCursors(), {
position: new Position(lineNumber, column) position: new Position(lineNumber, column)
}); });
} else { } else {
CoreNavigationCommands.MoveTo.runCoreEditorCommand(viewModel.getCursors(), { CoreNavigationCommands.MoveTo.runCoreEditorCommand(editor, viewModel, viewModel.getCursors(), {
position: new Position(lineNumber, column) position: new Position(lineNumber, column)
}); });
} }
} }
function moveToEndOfLine(viewModel: ViewModel, inSelectionMode: boolean = false) { function moveToEndOfLine(editor: ITestCodeEditor, viewModel: ViewModel, inSelectionMode: boolean = false) {
if (inSelectionMode) { if (inSelectionMode) {
CoreNavigationCommands.CursorEndSelect.runCoreEditorCommand(viewModel.getCursors(), {}); CoreNavigationCommands.CursorEndSelect.runCoreEditorCommand(editor, viewModel, viewModel.getCursors(), {});
} else { } else {
CoreNavigationCommands.CursorEnd.runCoreEditorCommand(viewModel.getCursors(), {}); CoreNavigationCommands.CursorEnd.runCoreEditorCommand(editor, viewModel, viewModel.getCursors(), {});
} }
} }
...@@ -47,6 +47,7 @@ export class ToggleColumnSelectionAction extends Action { ...@@ -47,6 +47,7 @@ export class ToggleColumnSelectionAction extends Action {
if (!codeEditor || codeEditor !== this._getCodeEditor() || oldValue === newValue || !codeEditor.hasModel()) { if (!codeEditor || codeEditor !== this._getCodeEditor() || oldValue === newValue || !codeEditor.hasModel()) {
return; return;
} }
const viewModel = codeEditor._getViewModel();
const cursors = codeEditor._getCursors(); const cursors = codeEditor._getCursors();
if (codeEditor.getOption(EditorOption.columnSelection)) { if (codeEditor.getOption(EditorOption.columnSelection)) {
const selection = codeEditor.getSelection(); const selection = codeEditor.getSelection();
...@@ -55,12 +56,12 @@ export class ToggleColumnSelectionAction extends Action { ...@@ -55,12 +56,12 @@ export class ToggleColumnSelectionAction extends Action {
const modelPosition = new Position(selection.positionLineNumber, selection.positionColumn); const modelPosition = new Position(selection.positionLineNumber, selection.positionColumn);
const viewPosition = cursors.context.coordinatesConverter.convertModelPositionToViewPosition(modelPosition); const viewPosition = cursors.context.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
CoreNavigationCommands.MoveTo.runCoreEditorCommand(cursors, { CoreNavigationCommands.MoveTo.runCoreEditorCommand(codeEditor, viewModel, cursors, {
position: modelSelectionStart, position: modelSelectionStart,
viewPosition: viewSelectionStart viewPosition: viewSelectionStart
}); });
const visibleColumn = CursorColumns.visibleColumnFromColumn2(cursors.context.config, cursors.context.viewModel, viewPosition); const visibleColumn = CursorColumns.visibleColumnFromColumn2(cursors.context.config, cursors.context.viewModel, viewPosition);
CoreNavigationCommands.ColumnSelect.runCoreEditorCommand(cursors, { CoreNavigationCommands.ColumnSelect.runCoreEditorCommand(codeEditor, viewModel, cursors, {
position: modelPosition, position: modelPosition,
viewPosition: viewPosition, viewPosition: viewPosition,
doColumnSelect: true, doColumnSelect: true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册