Small tweaks
This commit is contained in:
parent
a06c753e0b
commit
fc40df483d
6 changed files with 39 additions and 69 deletions
|
@ -226,11 +226,11 @@ export class View extends ViewEventHandler {
|
|||
// Pointer handler
|
||||
this.pointerHandler = this._register(new PointerHandler(this._context, viewController, this.createPointerHandlerHelper()));
|
||||
|
||||
this._register(model.addEventListener((events: viewEvents.ViewEvent[]) => {
|
||||
this._register(model.addViewEventListener((events: viewEvents.ViewEvent[]) => {
|
||||
this.eventDispatcher.emitMany(events);
|
||||
}));
|
||||
|
||||
this._register(this._cursor.addEventListener((events: viewEvents.ViewEvent[]) => {
|
||||
this._register(this._cursor.addViewEventListener((events: viewEvents.ViewEvent[]) => {
|
||||
this.eventDispatcher.emitMany(events);
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
|||
this._onModelContentChanged(e);
|
||||
}));
|
||||
|
||||
this._register(viewModel.addEventListener((events: viewEvents.ViewEvent[]) => {
|
||||
this._register(viewModel.addViewEventListener((events: viewEvents.ViewEvent[]) => {
|
||||
if (!containsLineMappingChanged(events)) {
|
||||
return;
|
||||
}
|
||||
|
@ -555,12 +555,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
|||
const viewSelections = this._cursors.getViewSelections();
|
||||
|
||||
// Let the view get the event first.
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewCursorStateChangedEvent(viewSelections, selections));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewCursorStateChangedEvent(viewSelections, selections));
|
||||
|
||||
// Only after the view has been notified, let the rest of the world know...
|
||||
if (!oldState
|
||||
|
@ -604,12 +599,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
|
|||
}
|
||||
|
||||
public emitCursorRevealRange(source: string, viewRange: Range | null, viewSelections: Selection[] | null, verticalType: viewEvents.VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType) {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, viewSelections, verticalType, revealHorizontal, scrollType));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewRevealRangeRequestEvent(source, viewRange, viewSelections, verticalType, revealHorizontal, scrollType));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -330,7 +330,11 @@ export interface IViewEventListener {
|
|||
(events: ViewEvent[]): void;
|
||||
}
|
||||
|
||||
export class ViewEventEmitter extends Disposable {
|
||||
export interface IViewEventEmitter {
|
||||
addViewEventListener(listener: IViewEventListener): IDisposable;
|
||||
}
|
||||
|
||||
export class ViewEventEmitter extends Disposable implements IViewEventEmitter {
|
||||
private _listeners: IViewEventListener[];
|
||||
private _collector: ViewEventsCollector | null;
|
||||
private _collectorCnt: number;
|
||||
|
@ -347,7 +351,7 @@ export class ViewEventEmitter extends Disposable {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
protected _beginEmit(): ViewEventsCollector {
|
||||
protected _beginEmitViewEvents(): ViewEventsCollector {
|
||||
this._collectorCnt++;
|
||||
if (this._collectorCnt === 1) {
|
||||
this._collector = new ViewEventsCollector();
|
||||
|
@ -355,7 +359,7 @@ export class ViewEventEmitter extends Disposable {
|
|||
return this._collector!;
|
||||
}
|
||||
|
||||
protected _endEmit(): void {
|
||||
protected _endEmitViewEvents(): void {
|
||||
this._collectorCnt--;
|
||||
if (this._collectorCnt === 0) {
|
||||
const events = this._collector!.finalize();
|
||||
|
@ -366,6 +370,15 @@ export class ViewEventEmitter extends Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
protected _emitSingleViewEvent(event: ViewEvent): void {
|
||||
try {
|
||||
const eventsCollector = this._beginEmitViewEvents();
|
||||
eventsCollector.emit(event);
|
||||
} finally {
|
||||
this._endEmitViewEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private _emit(events: ViewEvent[]): void {
|
||||
const listeners = this._listeners.slice(0);
|
||||
for (let i = 0, len = listeners.length; i < len; i++) {
|
||||
|
@ -373,7 +386,7 @@ export class ViewEventEmitter extends Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
public addEventListener(listener: (events: ViewEvent[]) => void): IDisposable {
|
||||
public addViewEventListener(listener: IViewEventListener): IDisposable {
|
||||
this._listeners.push(listener);
|
||||
return toDisposable(() => {
|
||||
let listeners = this._listeners;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IScrollPosition, Scrollable } from 'vs/base/common/scrollable';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { IViewLineTokens } from 'vs/editor/common/core/lineTokens';
|
||||
|
@ -11,7 +10,7 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
|
|||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { INewScrollPosition } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLinePreference, IActiveIndentGuideInfo, IModelDecorationOptions, TextModelResolvedOptions } from 'vs/editor/common/model';
|
||||
import { IViewEventListener } from 'vs/editor/common/view/viewEvents';
|
||||
import { IViewEventEmitter } from 'vs/editor/common/view/viewEvents';
|
||||
import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
|
||||
import { IEditorWhitespace, IWhitespaceChangeAccessor } from 'vs/editor/common/viewLayout/linesLayout';
|
||||
import { EditorTheme } from 'vs/editor/common/view/viewContext';
|
||||
|
@ -95,9 +94,7 @@ export interface ICoordinatesConverter {
|
|||
modelPositionIsVisible(modelPosition: Position): boolean;
|
||||
}
|
||||
|
||||
export interface IViewModel {
|
||||
|
||||
addEventListener(listener: IViewEventListener): IDisposable;
|
||||
export interface IViewModel extends IViewEventEmitter {
|
||||
|
||||
readonly coordinatesConverter: ICoordinatesConverter;
|
||||
|
||||
|
|
|
@ -94,21 +94,11 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
if (e.scrollTopChanged) {
|
||||
this._tokenizeViewportSoon.schedule();
|
||||
}
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewScrollChangedEvent(e));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewScrollChangedEvent(e));
|
||||
}));
|
||||
|
||||
this._register(this.viewLayout.onDidContentSizeChange((e) => {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewContentSizeChangedEvent(e));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewContentSizeChangedEvent(e));
|
||||
}));
|
||||
|
||||
this.decorations = new ViewModelDecorations(this.editorId, this.model, this.configuration, this.lines, this.coordinatesConverter);
|
||||
|
@ -117,20 +107,15 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
|
||||
this._register(this.configuration.onDidChange((e) => {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
const eventsCollector = this._beginEmitViewEvents();
|
||||
this._onConfigurationChanged(eventsCollector, e);
|
||||
} finally {
|
||||
this._endEmit();
|
||||
this._endEmitViewEvents();
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(MinimapTokensColorTracker.getInstance().onDidChange(() => {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewTokensColorsChangedEvent());
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewTokensColorsChangedEvent());
|
||||
}));
|
||||
|
||||
this._updateConfigurationViewLineCountNow();
|
||||
|
@ -212,7 +197,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
|
||||
this._register(this.model.onDidChangeRawContentFast((e) => {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
const eventsCollector = this._beginEmitViewEvents();
|
||||
|
||||
let hadOtherModelChange = false;
|
||||
let hadModelLineChangeThatChangedLineMapping = false;
|
||||
|
@ -305,7 +290,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
this.decorations.onLineMappingChanged();
|
||||
}
|
||||
} finally {
|
||||
this._endEmit();
|
||||
this._endEmitViewEvents();
|
||||
}
|
||||
|
||||
// Update the configuration and reset the centered view line
|
||||
|
@ -335,12 +320,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
toLineNumber: viewEndLineNumber
|
||||
};
|
||||
}
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewTokensChangedEvent(viewRanges));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewTokensChangedEvent(viewRanges));
|
||||
|
||||
if (e.tokenizationSupportChanged) {
|
||||
this._tokenizeViewportSoon.schedule();
|
||||
|
@ -348,12 +328,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
}));
|
||||
|
||||
this._register(this.model.onDidChangeLanguageConfiguration((e) => {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewLanguageConfigurationEvent());
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewLanguageConfigurationEvent());
|
||||
}));
|
||||
|
||||
this._register(this.model.onDidChangeOptions((e) => {
|
||||
|
@ -362,12 +337,12 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
this.decorations.onLineMappingChanged();
|
||||
this.viewLayout.onFlushed(this.getLineCount());
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
const eventsCollector = this._beginEmitViewEvents();
|
||||
eventsCollector.emit(new viewEvents.ViewFlushedEvent());
|
||||
eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent());
|
||||
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(null));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
this._endEmitViewEvents();
|
||||
}
|
||||
this._updateConfigurationViewLineCount.schedule();
|
||||
}
|
||||
|
@ -375,18 +350,13 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
|
||||
this._register(this.model.onDidChangeDecorations((e) => {
|
||||
this.decorations.onModelDecorationsChanged();
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent(e));
|
||||
} finally {
|
||||
this._endEmit();
|
||||
}
|
||||
this._emitSingleViewEvent(new viewEvents.ViewDecorationsChangedEvent(e));
|
||||
}));
|
||||
}
|
||||
|
||||
public setHiddenAreas(ranges: Range[]): void {
|
||||
try {
|
||||
const eventsCollector = this._beginEmit();
|
||||
const eventsCollector = this._beginEmitViewEvents();
|
||||
let lineMappingChanged = this.lines.setHiddenAreas(ranges);
|
||||
if (lineMappingChanged) {
|
||||
eventsCollector.emit(new viewEvents.ViewFlushedEvent());
|
||||
|
@ -397,7 +367,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
|
|||
this.viewLayout.onHeightMaybeChanged();
|
||||
}
|
||||
} finally {
|
||||
this._endEmit();
|
||||
this._endEmitViewEvents();
|
||||
}
|
||||
this._updateConfigurationViewLineCount.schedule();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ suite('ViewModel', () => {
|
|||
let viewLineCount: number[] = [];
|
||||
|
||||
viewLineCount.push(viewModel.getLineCount());
|
||||
viewModel.addEventListener((events) => {
|
||||
viewModel.addViewEventListener((events) => {
|
||||
// Access the view model
|
||||
viewLineCount.push(viewModel.getLineCount());
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue