提交 a47159ba 编写于 作者: A Alex Dima

Eliminate IModelDecorationsChangedEvent.changedDecorations

上级 6023aee9
......@@ -88,10 +88,6 @@ export interface IModelContentChangedEvent {
* An event describing that model decorations have changed.
*/
export interface IModelDecorationsChangedEvent {
/**
* Lists of ids for changed decorations.
*/
readonly changedDecorations: string[];
}
/**
......
......@@ -28,15 +28,12 @@ class DecorationsTracker {
public didAddDecorations: boolean;
public didRemoveDecorations: boolean;
public changedDecorations: string[];
public changedDecorationsLen: number;
public didChangeDecorations: boolean;
constructor() {
this.didAddDecorations = false;
this.didRemoveDecorations = false;
this.changedDecorations = [];
this.changedDecorationsLen = 0;
this.didChangeDecorations = false;
}
// --- Build decoration events
......@@ -49,12 +46,8 @@ class DecorationsTracker {
this.didRemoveDecorations = true;
}
public addMovedDecoration(id: string): void {
this.changedDecorations[this.changedDecorationsLen++] = id;
}
public addUpdatedDecoration(id: string): void {
this.changedDecorations[this.changedDecorationsLen++] = id;
public markDidChangeDecorations(): void {
this.didChangeDecorations = true;
}
}
......@@ -456,7 +449,7 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
}
/**
* Handle changed markers (i.e. update decorations ranges and return the changed decorations, unique and sorted by id)
* Handle changed markers (i.e. update decorations ranges)
*/
private _handleTrackedMarkers(markersTracker: MarkersTracker): void {
let changedInternalDecorationIds = markersTracker.getDecorationIds();
......@@ -466,8 +459,8 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
changedInternalDecorationIds.sort();
let uniqueChangedDecorations: string[] = [], uniqueChangedDecorationsLen = 0;
let previousInternalDecorationId: number = 0;
let somethingChanged = false;
for (let i = 0, len = changedInternalDecorationIds.length; i < len; i++) {
let internalDecorationId = changedInternalDecorationIds[i];
if (internalDecorationId === previousInternalDecorationId) {
......@@ -485,15 +478,11 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
let endMarker = decoration.endMarker.position;
let range = TextModelWithDecorations._createRangeFromMarkers(startMarker, endMarker);
decoration.setRange(this._multiLineDecorationsMap, range);
uniqueChangedDecorations[uniqueChangedDecorationsLen++] = decoration.id;
somethingChanged = true;
}
if (uniqueChangedDecorations.length > 0) {
let e: textModelEvents.IModelDecorationsChangedEvent = {
changedDecorations: uniqueChangedDecorations
};
this.emitModelDecorationsChangedEvent(e);
if (somethingChanged) {
this.emitModelDecorationsChangedEvent();
}
}
......@@ -528,20 +517,18 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
private _handleTrackedDecorations(decorationsTracker: DecorationsTracker): void {
if (
!decorationsTracker.didAddDecorations
&& decorationsTracker.changedDecorationsLen === 0
&& !decorationsTracker.didChangeDecorations
&& !decorationsTracker.didRemoveDecorations
) {
return;
}
let e: textModelEvents.IModelDecorationsChangedEvent = {
changedDecorations: decorationsTracker.changedDecorations
};
this.emitModelDecorationsChangedEvent(e);
this.emitModelDecorationsChangedEvent();
}
private emitModelDecorationsChangedEvent(e: textModelEvents.IModelDecorationsChangedEvent): void {
private emitModelDecorationsChangedEvent(): void {
if (!this._isDisposing) {
let e: textModelEvents.IModelDecorationsChangedEvent = {};
this._eventEmitter.emit(textModelEvents.TextModelEventType.ModelDecorationsChanged, e);
}
}
......@@ -666,7 +653,7 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
decoration.setRange(this._multiLineDecorationsMap, newRange);
decorationsTracker.addMovedDecoration(decorationId);
decorationsTracker.markDidChangeDecorations();
}
private _changeDecorationOptionsImpl(decorationsTracker: DecorationsTracker, decorationId: string, options: ModelDecorationOptions): void {
......@@ -682,7 +669,7 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
decoration.setOptions(options);
decorationsTracker.addUpdatedDecoration(decorationId);
decorationsTracker.markDidChangeDecorations();
}
private _removeDecorationImpl(decorationsTracker: DecorationsTracker, decorationId: string): void {
......
......@@ -9,7 +9,6 @@ import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { InlineDecoration, ViewModelDecoration, ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';
export interface IDecorationsViewportData {
/**
......@@ -58,7 +57,7 @@ export class ViewModelDecorations implements IDisposable {
this._clearCachedModelDecorationsResolver();
}
public onModelDecorationsChanged(e: IModelDecorationsChangedEvent): void {
public onModelDecorationsChanged(): void {
this._decorationsCache = Object.create(null);
this._clearCachedModelDecorationsResolver();
}
......
......@@ -282,8 +282,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
break;
}
case textModelEvents.TextModelEventType.ModelDecorationsChanged: {
const e = <textModelEvents.IModelDecorationsChangedEvent>data;
this.decorations.onModelDecorationsChanged(e);
this.decorations.onModelDecorationsChanged();
eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent());
break;
}
......
......@@ -38,7 +38,6 @@ import { ITextModelService, ITextEditorModel } from 'vs/editor/common/services/r
import { registerColor, activeContrastBorder, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { registerThemingParticipant, ITheme, IThemeService } from 'vs/platform/theme/common/themeService';
import { attachListStyler, attachBadgeStyler } from 'vs/platform/theme/common/styler';
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
......@@ -81,7 +80,7 @@ class DecorationsManager implements IDisposable {
}
private _addDecorations(reference: FileReferences): void {
this._callOnModelChange.push(this._editor.getModel().onDidChangeDecorations((event) => this._onDecorationChanged(event)));
this._callOnModelChange.push(this._editor.getModel().onDidChangeDecorations((event) => this._onDecorationChanged()));
this._editor.changeDecorations(accessor => {
......@@ -107,7 +106,7 @@ class DecorationsManager implements IDisposable {
});
}
private _onDecorationChanged(event: IModelDecorationsChangedEvent): void {
private _onDecorationChanged(): void {
const toRemove: string[] = [];
this._decorations.forEach((reference, decorationId) => {
......
......@@ -207,7 +207,6 @@ suite('Editor Model - Model Decorations', () => {
let listenerCalled = 0;
thisModel.onDidChangeDecorations((e) => {
listenerCalled++;
assert.equal(e.changedDecorations.length, 0);
});
addDecoration(thisModel, 1, 2, 3, 2, 'myType');
assert.equal(listenerCalled, 1, 'listener called');
......@@ -218,8 +217,6 @@ suite('Editor Model - Model Decorations', () => {
let decId = addDecoration(thisModel, 1, 2, 3, 2, 'myType');
thisModel.onDidChangeDecorations((e) => {
listenerCalled++;
assert.equal(e.changedDecorations.length, 1);
assert.equal(e.changedDecorations[0], decId);
});
thisModel.changeDecorations((changeAccessor) => {
changeAccessor.changeDecoration(decId, new Range(1, 1, 1, 2));
......@@ -232,7 +229,6 @@ suite('Editor Model - Model Decorations', () => {
let decId = addDecoration(thisModel, 1, 2, 3, 2, 'myType');
thisModel.onDidChangeDecorations((e) => {
listenerCalled++;
assert.equal(e.changedDecorations.length, 0);
});
thisModel.changeDecorations((changeAccessor) => {
changeAccessor.removeDecoration(decId);
......@@ -242,12 +238,10 @@ suite('Editor Model - Model Decorations', () => {
test('decorations emit event when inserting one line text before it', () => {
let listenerCalled = 0;
let decId = addDecoration(thisModel, 1, 2, 3, 2, 'myType');
addDecoration(thisModel, 1, 2, 3, 2, 'myType');
thisModel.onDidChangeDecorations((e) => {
listenerCalled++;
assert.equal(e.changedDecorations.length, 1);
assert.equal(e.changedDecorations[0], decId);
});
thisModel.applyEdits([EditOperation.insert(new Position(1, 1), 'Hallo ')]);
......
......@@ -2482,10 +2482,6 @@ declare module monaco.editor {
* An event describing that model decorations have changed.
*/
export interface IModelDecorationsChangedEvent {
/**
* Lists of ids for changed decorations.
*/
readonly changedDecorations: string[];
}
/**
......
......@@ -13,7 +13,6 @@ import { IModel, TrackedRangeStickiness, IModelDeltaDecoration, IModelDecoration
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IDebugService, IBreakpoint, IRawBreakpoint, State } from 'vs/workbench/parts/debug/common/debug';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';
import { MarkdownString } from 'vs/base/common/htmlContent';
interface IDebugEditorModelData {
......@@ -84,7 +83,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
const desiredDecorations = this.createBreakpointDecorations(model, breakpoints);
const breakPointDecorations = model.deltaDecorations([], desiredDecorations);
const toDispose: lifecycle.IDisposable[] = [model.onDidChangeDecorations((e) => this.onModelDecorationsChanged(modelUrlStr, e))];
const toDispose: lifecycle.IDisposable[] = [model.onDidChangeDecorations((e) => this.onModelDecorationsChanged(modelUrlStr))];
const breakpointDecorationsAsMap = new Map<string, Range>();
breakPointDecorations.forEach((decorationId, index) => breakpointDecorationsAsMap.set(decorationId, desiredDecorations[index].range));
......@@ -186,7 +185,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
}
// breakpoints management. Represent data coming from the debug service and also send data back.
private onModelDecorationsChanged(modelUrlStr: string, e: IModelDecorationsChangedEvent): void {
private onModelDecorationsChanged(modelUrlStr: string): void {
const modelData = this.modelDataMap.get(modelUrlStr);
if (modelData.breakpointDecorationsAsMap.size === 0) {
// I have no decorations
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册