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

Eliminate IModelDecorationsChangedEvent.changedDecorations

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