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

Emit cursor state change events through view model

上级 4ba9ad5d
...@@ -23,7 +23,7 @@ import { ICommandDelegate } from 'vs/editor/browser/view/viewController'; ...@@ -23,7 +23,7 @@ import { ICommandDelegate } from 'vs/editor/browser/view/viewController';
import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl'; import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl';
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents'; import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, IEditorConstructionOptions, filterValidationDecorations } from 'vs/editor/common/config/editorOptions'; import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById, IEditorConstructionOptions, filterValidationDecorations } from 'vs/editor/common/config/editorOptions';
import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor'; import { Cursor } from 'vs/editor/common/controller/cursor';
import { CursorColumns } from 'vs/editor/common/controller/cursorCommon'; import { CursorColumns } from 'vs/editor/common/controller/cursorCommon';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { IPosition, Position } from 'vs/editor/common/core/position'; import { IPosition, Position } from 'vs/editor/common/core/position';
...@@ -1477,36 +1477,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -1477,36 +1477,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this._onDidAttemptReadOnlyEdit.fire(undefined); this._onDidAttemptReadOnlyEdit.fire(undefined);
})); }));
listenersToRemove.push(viewModel.cursor.onDidChange((e: CursorStateChangedEvent) => {
if (e.reachedMaxCursorCount) {
this._notificationService.warn(nls.localize('cursors.maximum', "The number of cursors has been limited to {0}.", Cursor.MAX_CURSOR_COUNT));
}
const positions: Position[] = [];
for (let i = 0, len = e.selections.length; i < len; i++) {
positions[i] = e.selections[i].getPosition();
}
const e1: ICursorPositionChangedEvent = {
position: positions[0],
secondaryPositions: positions.slice(1),
reason: e.reason,
source: e.source
};
this._onDidChangeCursorPosition.fire(e1);
const e2: ICursorSelectionChangedEvent = {
selection: e.selections[0],
secondarySelections: e.selections.slice(1),
modelVersionId: e.modelVersionId,
oldSelections: e.oldSelections,
oldModelVersionId: e.oldModelVersionId,
source: e.source,
reason: e.reason
};
this._onDidChangeCursorSelection.fire(e2);
}));
listenersToRemove.push(viewModel.onEvent((e) => { listenersToRemove.push(viewModel.onEvent((e) => {
switch (e.kind) { switch (e.kind) {
case OutgoingViewModelEventKind.ContentSizeChanged: case OutgoingViewModelEventKind.ContentSizeChanged:
...@@ -1521,6 +1491,38 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE ...@@ -1521,6 +1491,38 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
case OutgoingViewModelEventKind.ViewZonesChanged: case OutgoingViewModelEventKind.ViewZonesChanged:
this._onDidChangeViewZones.fire(); this._onDidChangeViewZones.fire();
break; break;
case OutgoingViewModelEventKind.CursorStateChanged: {
if (e.reachedMaxCursorCount) {
this._notificationService.warn(nls.localize('cursors.maximum', "The number of cursors has been limited to {0}.", Cursor.MAX_CURSOR_COUNT));
}
const positions: Position[] = [];
for (let i = 0, len = e.selections.length; i < len; i++) {
positions[i] = e.selections[i].getPosition();
}
const e1: ICursorPositionChangedEvent = {
position: positions[0],
secondaryPositions: positions.slice(1),
reason: e.reason,
source: e.source
};
this._onDidChangeCursorPosition.fire(e1);
const e2: ICursorSelectionChangedEvent = {
selection: e.selections[0],
secondarySelections: e.selections.slice(1),
modelVersionId: e.modelVersionId,
oldSelections: e.oldSelections,
oldModelVersionId: e.oldModelVersionId,
source: e.source,
reason: e.reason
};
this._onDidChangeCursorSelection.fire(e2);
break;
}
} }
})); }));
......
...@@ -17,51 +17,10 @@ import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core ...@@ -17,51 +17,10 @@ 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 } from 'vs/editor/common/model/textModelEvents'; import { RawContentChangedType, ModelRawContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
import { ViewEventsCollector, VerticalRevealType, ViewCursorStateChangedEvent, ViewRevealRangeRequestEvent } from 'vs/editor/common/view/viewEvents'; import { VerticalRevealType, ViewCursorStateChangedEvent, ViewRevealRangeRequestEvent } from 'vs/editor/common/view/viewEvents';
import { dispose, Disposable } from 'vs/base/common/lifecycle'; import { dispose, Disposable } from 'vs/base/common/lifecycle';
import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel'; import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
import { CursorStateChangedEvent, ViewModelEventsCollector } from 'vs/editor/common/viewModel/viewModelEventDispatcher';
export class CursorStateChangedEvent {
/**
* The new selections.
* The primary selection is always at index 0.
*/
readonly selections: Selection[];
/**
* The new model version id that `selections` apply to.
*/
readonly modelVersionId: number;
/**
* The old selections.
*/
readonly oldSelections: Selection[] | null;
/**
* The model version id the that `oldSelections` apply to.
*/
readonly oldModelVersionId: number;
/**
* Source of the call that caused the event.
*/
readonly source: string;
/**
* Reason.
*/
readonly reason: CursorChangeReason;
/**
* The number of cursors was limited because it has reached the maximum cursor count.
*/
readonly reachedMaxCursorCount: boolean;
constructor(selections: Selection[], modelVersionId: number, oldSelections: Selection[] | null, oldModelVersionId: number, source: string, reason: CursorChangeReason, reachedMaxCursorCount: boolean) {
this.selections = selections;
this.modelVersionId = modelVersionId;
this.oldSelections = oldSelections;
this.oldModelVersionId = oldModelVersionId;
this.source = source;
this.reason = reason;
this.reachedMaxCursorCount = reachedMaxCursorCount;
}
}
/** /**
* A snapshot of the cursor and the model state * A snapshot of the cursor and the model state
...@@ -168,9 +127,6 @@ export class Cursor extends Disposable { ...@@ -168,9 +127,6 @@ export class Cursor extends Disposable {
private readonly _onDidAttemptReadOnlyEdit: Emitter<void> = this._register(new Emitter<void>()); private readonly _onDidAttemptReadOnlyEdit: Emitter<void> = this._register(new Emitter<void>());
public readonly onDidAttemptReadOnlyEdit: Event<void> = this._onDidAttemptReadOnlyEdit.event; public readonly onDidAttemptReadOnlyEdit: Event<void> = this._onDidAttemptReadOnlyEdit.event;
private readonly _onDidChange: Emitter<CursorStateChangedEvent> = this._register(new Emitter<CursorStateChangedEvent>());
public readonly onDidChange: Event<CursorStateChangedEvent> = this._onDidChange.event;
private readonly _model: ITextModel; private readonly _model: ITextModel;
private _knownModelVersionId: number; private _knownModelVersionId: number;
private readonly _viewModel: ICursorSimpleModel; private readonly _viewModel: ICursorSimpleModel;
...@@ -215,7 +171,7 @@ export class Cursor extends Disposable { ...@@ -215,7 +171,7 @@ export class Cursor extends Disposable {
this._cursors.updateContext(this.context); this._cursors.updateContext(this.context);
} }
public onLineMappingChanged(eventsCollector: ViewEventsCollector): void { public onLineMappingChanged(eventsCollector: ViewModelEventsCollector): 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.
// //
...@@ -262,7 +218,7 @@ export class Cursor extends Disposable { ...@@ -262,7 +218,7 @@ export class Cursor extends Disposable {
return this._cursors.getAll(); return this._cursors.getAll();
} }
public setStates(eventsCollector: ViewEventsCollector, source: string | null | undefined, reason: CursorChangeReason, states: PartialCursorState[] | null): boolean { public setStates(eventsCollector: ViewModelEventsCollector, 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);
...@@ -284,7 +240,7 @@ export class Cursor extends Disposable { ...@@ -284,7 +240,7 @@ export class Cursor extends Disposable {
this._columnSelectData = columnSelectData; this._columnSelectData = columnSelectData;
} }
public revealPrimary(eventsCollector: ViewEventsCollector, source: string | null | undefined, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void { public revealPrimary(eventsCollector: ViewModelEventsCollector, source: string | null | undefined, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
const viewPositions = this._cursors.getViewPositions(); const viewPositions = this._cursors.getViewPositions();
if (viewPositions.length > 1) { if (viewPositions.length > 1) {
this._emitCursorRevealRange(eventsCollector, source, null, this._cursors.getViewSelections(), VerticalRevealType.Simple, revealHorizontal, scrollType); this._emitCursorRevealRange(eventsCollector, source, null, this._cursors.getViewSelections(), VerticalRevealType.Simple, revealHorizontal, scrollType);
...@@ -296,7 +252,7 @@ export class Cursor extends Disposable { ...@@ -296,7 +252,7 @@ export class Cursor extends Disposable {
} }
} }
private _revealPrimaryCursor(eventsCollector: ViewEventsCollector, source: string | null | undefined, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void { private _revealPrimaryCursor(eventsCollector: ViewModelEventsCollector, source: string | null | undefined, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
const viewPositions = this._cursors.getViewPositions(); const viewPositions = this._cursors.getViewPositions();
if (viewPositions.length > 1) { if (viewPositions.length > 1) {
this._emitCursorRevealRange(eventsCollector, source, null, this._cursors.getViewSelections(), verticalType, revealHorizontal, scrollType); this._emitCursorRevealRange(eventsCollector, source, null, this._cursors.getViewSelections(), verticalType, revealHorizontal, scrollType);
...@@ -307,8 +263,8 @@ export class Cursor extends Disposable { ...@@ -307,8 +263,8 @@ export class Cursor extends Disposable {
} }
} }
private _emitCursorRevealRange(eventsCollector: ViewEventsCollector, source: string | null | undefined, viewRange: Range | null, viewSelections: Selection[] | null, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) { private _emitCursorRevealRange(eventsCollector: ViewModelEventsCollector, 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)); eventsCollector.emitViewEvent(new ViewRevealRangeRequestEvent(source, viewRange, viewSelections, verticalType, revealHorizontal, scrollType));
} }
public saveState(): editorCommon.ICursorState[] { public saveState(): editorCommon.ICursorState[] {
...@@ -335,7 +291,7 @@ export class Cursor extends Disposable { ...@@ -335,7 +291,7 @@ export class Cursor extends Disposable {
return result; return result;
} }
public restoreState(eventsCollector: ViewEventsCollector, states: editorCommon.ICursorState[]): void { public restoreState(eventsCollector: ViewModelEventsCollector, states: editorCommon.ICursorState[]): void {
let desiredSelections: ISelection[] = []; let desiredSelections: ISelection[] = [];
...@@ -376,7 +332,7 @@ export class Cursor extends Disposable { ...@@ -376,7 +332,7 @@ export class Cursor extends Disposable {
this.revealPrimary(eventsCollector, 'restoreState', true, editorCommon.ScrollType.Immediate); this.revealPrimary(eventsCollector, 'restoreState', true, editorCommon.ScrollType.Immediate);
} }
public onModelContentChanged(eventsCollector: ViewEventsCollector, e: ModelRawContentChangedEvent): void { public onModelContentChanged(eventsCollector: ViewModelEventsCollector, e: ModelRawContentChangedEvent): void {
this._knownModelVersionId = e.versionId; this._knownModelVersionId = e.versionId;
if (this._isHandling) { if (this._isHandling) {
...@@ -441,7 +397,7 @@ export class Cursor extends Disposable { ...@@ -441,7 +397,7 @@ export class Cursor extends Disposable {
return this._cursors.getPrimaryCursor().modelState.position; return this._cursors.getPrimaryCursor().modelState.position;
} }
public setSelections(eventsCollector: ViewEventsCollector, source: string | null | undefined, selections: readonly ISelection[]): void { public setSelections(eventsCollector: ViewModelEventsCollector, source: string | null | undefined, selections: readonly ISelection[]): void {
this.setStates(eventsCollector, source, CursorChangeReason.NotSet, CursorState.fromModelSelections(selections)); this.setStates(eventsCollector, source, CursorChangeReason.NotSet, CursorState.fromModelSelections(selections));
} }
...@@ -533,7 +489,7 @@ export class Cursor extends Disposable { ...@@ -533,7 +489,7 @@ export class Cursor extends Disposable {
// ----------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------
// ----- emitting events // ----- emitting events
private _emitStateChangedIfNecessary(eventsCollector: ViewEventsCollector, source: string | null | undefined, reason: CursorChangeReason, oldState: CursorModelState | null, reachedMaxCursorCount: boolean): boolean { private _emitStateChangedIfNecessary(eventsCollector: ViewModelEventsCollector, 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;
...@@ -543,7 +499,7 @@ export class Cursor extends Disposable { ...@@ -543,7 +499,7 @@ export class Cursor extends Disposable {
const viewSelections = this._cursors.getViewSelections(); const viewSelections = this._cursors.getViewSelections();
// Let the view get the event first. // Let the view get the event first.
eventsCollector.emit(new ViewCursorStateChangedEvent(viewSelections, selections)); eventsCollector.emitViewEvent(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,7 +508,7 @@ export class Cursor extends Disposable { ...@@ -552,7 +508,7 @@ export class Cursor extends Disposable {
) { ) {
const oldSelections = oldState ? oldState.cursorState.map(s => s.modelState.selection) : null; const oldSelections = oldState ? oldState.cursorState.map(s => s.modelState.selection) : null;
const oldModelVersionId = oldState ? oldState.modelVersionId : 0; const oldModelVersionId = oldState ? oldState.modelVersionId : 0;
this._onDidChange.fire(new CursorStateChangedEvent(selections, newState.modelVersionId, oldSelections, oldModelVersionId, source || 'keyboard', reason, reachedMaxCursorCount)); eventsCollector.emitOutgoingEvent(new CursorStateChangedEvent(oldSelections, selections, oldModelVersionId, newState.modelVersionId, source || 'keyboard', reason, reachedMaxCursorCount));
} }
return true; return true;
...@@ -597,7 +553,7 @@ export class Cursor extends Disposable { ...@@ -597,7 +553,7 @@ export class Cursor extends Disposable {
return indices; return indices;
} }
public executeEdits(eventsCollector: ViewEventsCollector, source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): void { public executeEdits(eventsCollector: ViewModelEventsCollector, 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);
...@@ -639,7 +595,7 @@ export class Cursor extends Disposable { ...@@ -639,7 +595,7 @@ export class Cursor extends Disposable {
} }
} }
private _executeEdit(callback: () => void, eventsCollector: ViewEventsCollector, source: string | null | undefined, cursorChangeReason: CursorChangeReason = CursorChangeReason.NotSet): void { private _executeEdit(callback: () => void, eventsCollector: ViewModelEventsCollector, source: string | null | undefined, cursorChangeReason: CursorChangeReason = CursorChangeReason.NotSet): void {
if (this.context.cursorConfig.readOnly) { if (this.context.cursorConfig.readOnly) {
// we cannot edit when read only... // we cannot edit when read only...
this._onDidAttemptReadOnlyEdit.fire(undefined); this._onDidAttemptReadOnlyEdit.fire(undefined);
...@@ -665,12 +621,12 @@ export class Cursor extends Disposable { ...@@ -665,12 +621,12 @@ export class Cursor extends Disposable {
} }
} }
public startComposition(eventsCollector: ViewEventsCollector): void { public startComposition(eventsCollector: ViewModelEventsCollector): void {
this._isDoingComposition = true; this._isDoingComposition = true;
this._selectionsWhenCompositionStarted = this.getSelections().slice(0); this._selectionsWhenCompositionStarted = this.getSelections().slice(0);
} }
public endComposition(eventsCollector: ViewEventsCollector, source?: string | null | undefined): void { public endComposition(eventsCollector: ViewModelEventsCollector, 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') {
...@@ -682,7 +638,7 @@ export class Cursor extends Disposable { ...@@ -682,7 +638,7 @@ export class Cursor extends Disposable {
}, eventsCollector, source); }, eventsCollector, source);
} }
public type(eventsCollector: ViewEventsCollector, text: string, source?: string | null | undefined): void { public type(eventsCollector: ViewModelEventsCollector, 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
...@@ -706,25 +662,25 @@ export class Cursor extends Disposable { ...@@ -706,25 +662,25 @@ export class Cursor extends Disposable {
}, eventsCollector, source); }, eventsCollector, source);
} }
public replacePreviousChar(eventsCollector: ViewEventsCollector, text: string, replaceCharCnt: number, source?: string | null | undefined): void { public replacePreviousChar(eventsCollector: ViewModelEventsCollector, text: string, replaceCharCnt: number, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, this.context.cursorConfig, this._model, this.getSelections(), text, replaceCharCnt)); this._executeEditOperation(TypeOperations.replacePreviousChar(this._prevEditOperationType, this.context.cursorConfig, this._model, this.getSelections(), text, replaceCharCnt));
}, eventsCollector, source); }, eventsCollector, source);
} }
public paste(eventsCollector: ViewEventsCollector, text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void { public paste(eventsCollector: ViewModelEventsCollector, text: string, pasteOnNewLine: boolean, multicursorText?: string[] | null | undefined, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(TypeOperations.paste(this.context.cursorConfig, this._model, this.getSelections(), text, pasteOnNewLine, multicursorText || [])); this._executeEditOperation(TypeOperations.paste(this.context.cursorConfig, this._model, this.getSelections(), text, pasteOnNewLine, multicursorText || []));
}, eventsCollector, source, CursorChangeReason.Paste); }, eventsCollector, source, CursorChangeReason.Paste);
} }
public cut(eventsCollector: ViewEventsCollector, source?: string | null | undefined): void { public cut(eventsCollector: ViewModelEventsCollector, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._executeEditOperation(DeleteOperations.cut(this.context.cursorConfig, this._model, this.getSelections())); this._executeEditOperation(DeleteOperations.cut(this.context.cursorConfig, this._model, this.getSelections()));
}, eventsCollector, source); }, eventsCollector, source);
} }
public executeCommand(eventsCollector: ViewEventsCollector, command: editorCommon.ICommand, source?: string | null | undefined): void { public executeCommand(eventsCollector: ViewModelEventsCollector, command: editorCommon.ICommand, source?: string | null | undefined): void {
this._executeEdit(() => { this._executeEdit(() => {
this._cursors.killSecondaryCursors(); this._cursors.killSecondaryCursors();
...@@ -735,7 +691,7 @@ export class Cursor extends Disposable { ...@@ -735,7 +691,7 @@ export class Cursor extends Disposable {
}, eventsCollector, source); }, eventsCollector, source);
} }
public executeCommands(eventsCollector: ViewEventsCollector, commands: editorCommon.ICommand[], source?: string | null | undefined): void { public executeCommands(eventsCollector: ViewModelEventsCollector, 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,
......
...@@ -302,24 +302,3 @@ export type ViewEvent = ( ...@@ -302,24 +302,3 @@ export type ViewEvent = (
| ViewTokensColorsChangedEvent | ViewTokensColorsChangedEvent
| ViewZonesChangedEvent | ViewZonesChangedEvent
); );
export class ViewEventsCollector {
private _events: ViewEvent[];
private _eventsLen = 0;
constructor() {
this._events = [];
this._eventsLen = 0;
}
public emit(event: ViewEvent) {
this._events[this._eventsLen++] = event;
}
public finalize(): ViewEvent[] {
let result = this._events;
this._events = [];
return result;
}
}
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler';
import { ViewEvent, ViewEventsCollector } from 'vs/editor/common/view/viewEvents'; import { ViewEvent } from 'vs/editor/common/view/viewEvents';
import { IContentSizeChangedEvent } from 'vs/editor/common/editorCommon'; import { IContentSizeChangedEvent } from 'vs/editor/common/editorCommon';
import { Emitter } from 'vs/base/common/event'; import { Emitter } from 'vs/base/common/event';
import { Selection } from 'vs/editor/common/core/selection';
import { Disposable } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
export class ViewModelEventDispatcher extends Disposable { export class ViewModelEventDispatcher extends Disposable {
...@@ -17,7 +19,7 @@ export class ViewModelEventDispatcher extends Disposable { ...@@ -17,7 +19,7 @@ export class ViewModelEventDispatcher extends Disposable {
private readonly _eventHandlers: ViewEventHandler[]; private readonly _eventHandlers: ViewEventHandler[];
private _viewEventQueue: ViewEvent[] | null; private _viewEventQueue: ViewEvent[] | null;
private _isConsumingViewEventQueue: boolean; private _isConsumingViewEventQueue: boolean;
private _collector: ViewEventsCollector | null; private _collector: ViewModelEventsCollector | null;
private _collectorCnt: number; private _collectorCnt: number;
private _outgoingEvents: OutgoingViewModelEvent[]; private _outgoingEvents: OutgoingViewModelEvent[];
...@@ -79,10 +81,10 @@ export class ViewModelEventDispatcher extends Disposable { ...@@ -79,10 +81,10 @@ export class ViewModelEventDispatcher extends Disposable {
} }
} }
public beginEmitViewEvents(): ViewEventsCollector { public beginEmitViewEvents(): ViewModelEventsCollector {
this._collectorCnt++; this._collectorCnt++;
if (this._collectorCnt === 1) { if (this._collectorCnt === 1) {
this._collector = new ViewEventsCollector(); this._collector = new ViewModelEventsCollector();
} }
return this._collector!; return this._collector!;
} }
...@@ -90,10 +92,16 @@ export class ViewModelEventDispatcher extends Disposable { ...@@ -90,10 +92,16 @@ export class ViewModelEventDispatcher extends Disposable {
public endEmitViewEvents(): void { public endEmitViewEvents(): void {
this._collectorCnt--; this._collectorCnt--;
if (this._collectorCnt === 0) { if (this._collectorCnt === 0) {
const events = this._collector!.finalize(); const outgoingEvents = this._collector!.outgoingEvents;
const viewEvents = this._collector!.viewEvents;
this._collector = null; this._collector = null;
if (events.length > 0) {
this._emitMany(events); for (const outgoingEvent of outgoingEvents) {
this._addOutgoingEvent(outgoingEvent);
}
if (viewEvents.length > 0) {
this._emitMany(viewEvents);
} }
} }
this._emitOugoingEvents(); this._emitOugoingEvents();
...@@ -102,7 +110,7 @@ export class ViewModelEventDispatcher extends Disposable { ...@@ -102,7 +110,7 @@ export class ViewModelEventDispatcher extends Disposable {
public emitSingleViewEvent(event: ViewEvent): void { public emitSingleViewEvent(event: ViewEvent): void {
try { try {
const eventsCollector = this.beginEmitViewEvents(); const eventsCollector = this.beginEmitViewEvents();
eventsCollector.emit(event); eventsCollector.emitViewEvent(event);
} finally { } finally {
this.endEmitViewEvents(); this.endEmitViewEvents();
} }
...@@ -144,11 +152,31 @@ export class ViewModelEventDispatcher extends Disposable { ...@@ -144,11 +152,31 @@ export class ViewModelEventDispatcher extends Disposable {
} }
} }
export class ViewModelEventsCollector {
public readonly viewEvents: ViewEvent[];
public readonly outgoingEvents: OutgoingViewModelEvent[];
constructor() {
this.viewEvents = [];
this.outgoingEvents = [];
}
public emitViewEvent(event: ViewEvent) {
this.viewEvents.push(event);
}
public emitOutgoingEvent(e: OutgoingViewModelEvent): void {
this.outgoingEvents.push(e);
}
}
export const enum OutgoingViewModelEventKind { export const enum OutgoingViewModelEventKind {
ContentSizeChanged, ContentSizeChanged,
FocusChanged, FocusChanged,
ScrollChanged, ScrollChanged,
ViewZonesChanged, ViewZonesChanged,
CursorStateChanged,
} }
export class ContentSizeChangedEvent implements IContentSizeChangedEvent { export class ContentSizeChangedEvent implements IContentSizeChangedEvent {
...@@ -279,9 +307,69 @@ export class ViewZonesChangedEvent { ...@@ -279,9 +307,69 @@ export class ViewZonesChangedEvent {
} }
} }
export class CursorStateChangedEvent {
public readonly kind = OutgoingViewModelEventKind.CursorStateChanged;
public readonly oldSelections: Selection[] | null;
public readonly selections: Selection[];
public readonly oldModelVersionId: number;
public readonly modelVersionId: number;
public readonly source: string;
public readonly reason: CursorChangeReason;
public readonly reachedMaxCursorCount: boolean;
constructor(oldSelections: Selection[] | null, selections: Selection[], oldModelVersionId: number, modelVersionId: number, source: string, reason: CursorChangeReason, reachedMaxCursorCount: boolean) {
this.oldSelections = oldSelections;
this.selections = selections;
this.oldModelVersionId = oldModelVersionId;
this.modelVersionId = modelVersionId;
this.source = source;
this.reason = reason;
this.reachedMaxCursorCount = reachedMaxCursorCount;
}
private static _selectionsAreEqual(a: Selection[] | null, b: Selection[] | null): boolean {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
const aLen = a.length;
const bLen = b.length;
if (aLen !== bLen) {
return false;
}
for (let i = 0; i < aLen; i++) {
if (!a[i].equalsSelection(b[i])) {
return false;
}
}
return true;
}
public isNoOp(): boolean {
return (
CursorStateChangedEvent._selectionsAreEqual(this.oldSelections, this.selections)
&& this.oldModelVersionId === this.modelVersionId
);
}
public merge(other: OutgoingViewModelEvent): CursorStateChangedEvent {
if (other.kind !== OutgoingViewModelEventKind.CursorStateChanged) {
return this;
}
return new CursorStateChangedEvent(
this.oldSelections, other.selections, this.oldModelVersionId, other.modelVersionId, other.source, other.reason, this.reachedMaxCursorCount || other.reachedMaxCursorCount
);
}
}
export type OutgoingViewModelEvent = ( export type OutgoingViewModelEvent = (
ContentSizeChangedEvent ContentSizeChangedEvent
| FocusChangedEvent | FocusChangedEvent
| ScrollChangedEvent | ScrollChangedEvent
| ViewZonesChangedEvent | ViewZonesChangedEvent
| CursorStateChangedEvent
); );
...@@ -30,7 +30,7 @@ import { Cursor } from 'vs/editor/common/controller/cursor'; ...@@ -30,7 +30,7 @@ import { Cursor } from 'vs/editor/common/controller/cursor';
import { PartialCursorState, CursorState, IColumnSelectData, EditOperationType, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon'; import { PartialCursorState, CursorState, IColumnSelectData, EditOperationType, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout'; import { IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout';
import { ViewModelEventDispatcher, OutgoingViewModelEvent, FocusChangedEvent, ScrollChangedEvent, ViewZonesChangedEvent } from 'vs/editor/common/viewModel/viewModelEventDispatcher'; import { ViewModelEventDispatcher, OutgoingViewModelEvent, FocusChangedEvent, ScrollChangedEvent, ViewZonesChangedEvent, ViewModelEventsCollector } from 'vs/editor/common/viewModel/viewModelEventDispatcher';
import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler';
const USE_IDENTITY_LINES_COLLECTION = true; const USE_IDENTITY_LINES_COLLECTION = true;
...@@ -183,7 +183,7 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -183,7 +183,7 @@ export class ViewModel extends Disposable implements IViewModel {
this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewThemeChangedEvent()); this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewThemeChangedEvent());
} }
private _onConfigurationChanged(eventsCollector: viewEvents.ViewEventsCollector, e: ConfigurationChangedEvent): void { private _onConfigurationChanged(eventsCollector: ViewModelEventsCollector, e: ConfigurationChangedEvent): void {
// We might need to restore the current centered view range, so save it (if available) // We might need to restore the current centered view range, so save it (if available)
let previousViewportStartModelPosition: Position | null = null; let previousViewportStartModelPosition: Position | null = null;
...@@ -200,9 +200,9 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -200,9 +200,9 @@ export class ViewModel extends Disposable implements IViewModel {
const wrappingIndent = options.get(EditorOption.wrappingIndent); const wrappingIndent = options.get(EditorOption.wrappingIndent);
if (this.lines.setWrappingSettings(fontInfo, wrappingStrategy, wrappingInfo.wrappingColumn, wrappingIndent)) { if (this.lines.setWrappingSettings(fontInfo, wrappingStrategy, wrappingInfo.wrappingColumn, wrappingIndent)) {
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewFlushedEvent());
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emitViewEvent(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(eventsCollector); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount()); this.viewLayout.onFlushed(this.getLineCount());
...@@ -218,10 +218,10 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -218,10 +218,10 @@ export class ViewModel extends Disposable implements IViewModel {
if (e.hasChanged(EditorOption.readOnly)) { if (e.hasChanged(EditorOption.readOnly)) {
// Must read again all decorations due to readOnly filtering // Must read again all decorations due to readOnly filtering
this.decorations.reset(); this.decorations.reset();
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emitViewEvent(new viewEvents.ViewDecorationsChangedEvent(null));
} }
eventsCollector.emit(new viewEvents.ViewConfigurationChangedEvent(e)); eventsCollector.emitViewEvent(new viewEvents.ViewConfigurationChangedEvent(e));
this.viewLayout.onConfigurationChanged(e); this.viewLayout.onConfigurationChanged(e);
if (restorePreviousViewportStart && previousViewportStartModelPosition) { if (restorePreviousViewportStart && previousViewportStartModelPosition) {
...@@ -272,7 +272,7 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -272,7 +272,7 @@ export class ViewModel extends Disposable implements IViewModel {
switch (change.changeType) { switch (change.changeType) {
case textModelEvents.RawContentChangedType.Flush: { case textModelEvents.RawContentChangedType.Flush: {
this.lines.onModelFlushed(); this.lines.onModelFlushed();
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewFlushedEvent());
this.decorations.reset(); this.decorations.reset();
this.viewLayout.onFlushed(this.getLineCount()); this.viewLayout.onFlushed(this.getLineCount());
hadOtherModelChange = true; hadOtherModelChange = true;
...@@ -281,7 +281,7 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -281,7 +281,7 @@ export class ViewModel extends Disposable implements IViewModel {
case textModelEvents.RawContentChangedType.LinesDeleted: { case textModelEvents.RawContentChangedType.LinesDeleted: {
const linesDeletedEvent = this.lines.onModelLinesDeleted(versionId, change.fromLineNumber, change.toLineNumber); const linesDeletedEvent = this.lines.onModelLinesDeleted(versionId, change.fromLineNumber, change.toLineNumber);
if (linesDeletedEvent !== null) { if (linesDeletedEvent !== null) {
eventsCollector.emit(linesDeletedEvent); eventsCollector.emitViewEvent(linesDeletedEvent);
this.viewLayout.onLinesDeleted(linesDeletedEvent.fromLineNumber, linesDeletedEvent.toLineNumber); this.viewLayout.onLinesDeleted(linesDeletedEvent.fromLineNumber, linesDeletedEvent.toLineNumber);
} }
hadOtherModelChange = true; hadOtherModelChange = true;
...@@ -293,7 +293,7 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -293,7 +293,7 @@ export class ViewModel extends Disposable implements IViewModel {
const linesInsertedEvent = this.lines.onModelLinesInserted(versionId, change.fromLineNumber, change.toLineNumber, insertedLineBreaks); const linesInsertedEvent = this.lines.onModelLinesInserted(versionId, change.fromLineNumber, change.toLineNumber, insertedLineBreaks);
if (linesInsertedEvent !== null) { if (linesInsertedEvent !== null) {
eventsCollector.emit(linesInsertedEvent); eventsCollector.emitViewEvent(linesInsertedEvent);
this.viewLayout.onLinesInserted(linesInsertedEvent.fromLineNumber, linesInsertedEvent.toLineNumber); this.viewLayout.onLinesInserted(linesInsertedEvent.fromLineNumber, linesInsertedEvent.toLineNumber);
} }
hadOtherModelChange = true; hadOtherModelChange = true;
...@@ -306,14 +306,14 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -306,14 +306,14 @@ export class ViewModel extends Disposable implements IViewModel {
const [lineMappingChanged, linesChangedEvent, linesInsertedEvent, linesDeletedEvent] = this.lines.onModelLineChanged(versionId, change.lineNumber, changedLineBreakData); const [lineMappingChanged, linesChangedEvent, linesInsertedEvent, linesDeletedEvent] = this.lines.onModelLineChanged(versionId, change.lineNumber, changedLineBreakData);
hadModelLineChangeThatChangedLineMapping = lineMappingChanged; hadModelLineChangeThatChangedLineMapping = lineMappingChanged;
if (linesChangedEvent) { if (linesChangedEvent) {
eventsCollector.emit(linesChangedEvent); eventsCollector.emitViewEvent(linesChangedEvent);
} }
if (linesInsertedEvent) { if (linesInsertedEvent) {
eventsCollector.emit(linesInsertedEvent); eventsCollector.emitViewEvent(linesInsertedEvent);
this.viewLayout.onLinesInserted(linesInsertedEvent.fromLineNumber, linesInsertedEvent.toLineNumber); this.viewLayout.onLinesInserted(linesInsertedEvent.fromLineNumber, linesInsertedEvent.toLineNumber);
} }
if (linesDeletedEvent) { if (linesDeletedEvent) {
eventsCollector.emit(linesDeletedEvent); eventsCollector.emitViewEvent(linesDeletedEvent);
this.viewLayout.onLinesDeleted(linesDeletedEvent.fromLineNumber, linesDeletedEvent.toLineNumber); this.viewLayout.onLinesDeleted(linesDeletedEvent.fromLineNumber, linesDeletedEvent.toLineNumber);
} }
break; break;
...@@ -328,8 +328,8 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -328,8 +328,8 @@ export class ViewModel extends Disposable implements IViewModel {
this.viewLayout.onHeightMaybeChanged(); this.viewLayout.onHeightMaybeChanged();
if (!hadOtherModelChange && hadModelLineChangeThatChangedLineMapping) { if (!hadOtherModelChange && hadModelLineChangeThatChangedLineMapping) {
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emitViewEvent(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(eventsCollector); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
} }
...@@ -394,9 +394,9 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -394,9 +394,9 @@ export class ViewModel extends Disposable implements IViewModel {
if (this.lines.setTabSize(this.model.getOptions().tabSize)) { if (this.lines.setTabSize(this.model.getOptions().tabSize)) {
try { try {
const eventsCollector = this._eventDispatcher.beginEmitViewEvents(); const eventsCollector = this._eventDispatcher.beginEmitViewEvents();
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewFlushedEvent());
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emitViewEvent(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(eventsCollector); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount()); this.viewLayout.onFlushed(this.getLineCount());
...@@ -421,9 +421,9 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -421,9 +421,9 @@ export class ViewModel extends Disposable implements IViewModel {
const eventsCollector = this._eventDispatcher.beginEmitViewEvents(); const eventsCollector = this._eventDispatcher.beginEmitViewEvents();
let lineMappingChanged = this.lines.setHiddenAreas(ranges); let lineMappingChanged = this.lines.setHiddenAreas(ranges);
if (lineMappingChanged) { if (lineMappingChanged) {
eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewFlushedEvent());
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emitViewEvent(new viewEvents.ViewLineMappingChangedEvent());
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null)); eventsCollector.emitViewEvent(new viewEvents.ViewDecorationsChangedEvent(null));
this.cursor.onLineMappingChanged(eventsCollector); this.cursor.onLineMappingChanged(eventsCollector);
this.decorations.onLineMappingChanged(); this.decorations.onLineMappingChanged();
this.viewLayout.onFlushed(this.getLineCount()); this.viewLayout.onFlushed(this.getLineCount());
...@@ -947,15 +947,15 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -947,15 +947,15 @@ export class ViewModel extends Disposable implements IViewModel {
public revealTopMostCursor(source: string | null | undefined): void { public revealTopMostCursor(source: string | null | undefined): void {
const viewPosition = this.cursor.getTopMostViewPosition(); const viewPosition = this.cursor.getTopMostViewPosition();
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column); 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))); this._withViewEventsCollector(eventsCollector => eventsCollector.emitViewEvent(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, null, viewEvents.VerticalRevealType.Simple, true, ScrollType.Smooth)));
} }
public revealBottomMostCursor(source: string | null | undefined): void { public revealBottomMostCursor(source: string | null | undefined): void {
const viewPosition = this.cursor.getBottomMostViewPosition(); const viewPosition = this.cursor.getBottomMostViewPosition();
const viewRange = new Range(viewPosition.lineNumber, viewPosition.column, viewPosition.lineNumber, viewPosition.column); 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))); this._withViewEventsCollector(eventsCollector => eventsCollector.emitViewEvent(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 { 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))); this._withViewEventsCollector(eventsCollector => eventsCollector.emitViewEvent(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, null, verticalType, revealHorizontal, scrollType)));
} }
//#endregion //#endregion
...@@ -988,7 +988,7 @@ export class ViewModel extends Disposable implements IViewModel { ...@@ -988,7 +988,7 @@ export class ViewModel extends Disposable implements IViewModel {
} }
//#endregion //#endregion
private _withViewEventsCollector(callback: (eventsCollector: viewEvents.ViewEventsCollector) => void): void { private _withViewEventsCollector(callback: (eventsCollector: ViewModelEventsCollector) => void): void {
try { try {
const eventsCollector = this._eventDispatcher.beginEmitViewEvents(); const eventsCollector = this._eventDispatcher.beginEmitViewEvents();
callback(eventsCollector); callback(eventsCollector);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
import * as assert from 'assert'; import * as assert from 'assert';
import { CoreEditingCommands, CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands'; import { CoreEditingCommands, CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { CursorStateChangedEvent } from 'vs/editor/common/controller/cursor';
import { EditOperation } from 'vs/editor/common/core/editOperation'; import { EditOperation } from 'vs/editor/common/core/editOperation';
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';
...@@ -24,6 +23,7 @@ import { IRelaxedTextModelCreationOptions, createTextModel } from 'vs/editor/tes ...@@ -24,6 +23,7 @@ import { IRelaxedTextModelCreationOptions, createTextModel } from 'vs/editor/tes
import { MockMode } from 'vs/editor/test/common/mocks/mockMode'; import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules'; import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl'; import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
import { OutgoingViewModelEventKind } from 'vs/editor/common/viewModel/viewModelEventDispatcher';
// --------- utils // --------- utils
...@@ -782,7 +782,7 @@ suite('Editor Controller - Cursor', () => { ...@@ -782,7 +782,7 @@ suite('Editor Controller - Cursor', () => {
test('no move doesn\'t trigger event', () => { test('no move doesn\'t trigger event', () => {
runTest((editor, viewModel) => { runTest((editor, viewModel) => {
viewModel.cursor.onDidChange((e) => { viewModel.onEvent((e) => {
assert.ok(false, 'was not expecting event'); assert.ok(false, 'was not expecting event');
}); });
moveTo(editor, viewModel, 1, 1); moveTo(editor, viewModel, 1, 1);
...@@ -792,9 +792,13 @@ suite('Editor Controller - Cursor', () => { ...@@ -792,9 +792,13 @@ suite('Editor Controller - Cursor', () => {
test('move eventing', () => { test('move eventing', () => {
runTest((editor, viewModel) => { runTest((editor, viewModel) => {
let events = 0; let events = 0;
viewModel.cursor.onDidChange((e: CursorStateChangedEvent) => { viewModel.onEvent((e) => {
events++; if (e.kind === OutgoingViewModelEventKind.CursorStateChanged) {
assert.deepEqual(e.selections, [new Selection(1, 2, 1, 2)]); events++;
assert.deepEqual(e.selections, [new Selection(1, 2, 1, 2)]);
} else {
assert.ok(false);
}
}); });
moveTo(editor, viewModel, 1, 2); moveTo(editor, viewModel, 1, 2);
assert.equal(events, 1, 'receives 1 event'); assert.equal(events, 1, 'receives 1 event');
...@@ -804,9 +808,13 @@ suite('Editor Controller - Cursor', () => { ...@@ -804,9 +808,13 @@ suite('Editor Controller - Cursor', () => {
test('move in selection mode eventing', () => { test('move in selection mode eventing', () => {
runTest((editor, viewModel) => { runTest((editor, viewModel) => {
let events = 0; let events = 0;
viewModel.cursor.onDidChange((e: CursorStateChangedEvent) => { viewModel.onEvent((e) => {
events++; if (e.kind === OutgoingViewModelEventKind.CursorStateChanged) {
assert.deepEqual(e.selections, [new Selection(1, 1, 1, 2)]); events++;
assert.deepEqual(e.selections, [new Selection(1, 1, 1, 2)]);
} else {
assert.ok(false);
}
}); });
moveTo(editor, viewModel, 1, 2, true); moveTo(editor, viewModel, 1, 2, true);
assert.equal(events, 1, 'receives 1 event'); assert.equal(events, 1, 'receives 1 event');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册