From a47159bad1c1d0abdc5aae35b2f6f76524cfc869 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 12 Oct 2017 18:31:42 +0200 Subject: [PATCH] Eliminate IModelDecorationsChangedEvent.changedDecorations --- src/vs/editor/common/model/textModelEvents.ts | 4 -- .../common/model/textModelWithDecorations.ts | 43 +++++++------------ .../common/viewModel/viewModelDecorations.ts | 3 +- .../editor/common/viewModel/viewModelImpl.ts | 3 +- .../browser/referencesWidget.ts | 5 +-- .../common/model/modelDecorations.test.ts | 8 +--- src/vs/monaco.d.ts | 4 -- .../debug/browser/debugEditorModelManager.ts | 5 +-- 8 files changed, 22 insertions(+), 53 deletions(-) diff --git a/src/vs/editor/common/model/textModelEvents.ts b/src/vs/editor/common/model/textModelEvents.ts index a4c73b4cb13..aaa66c7beab 100644 --- a/src/vs/editor/common/model/textModelEvents.ts +++ b/src/vs/editor/common/model/textModelEvents.ts @@ -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[]; } /** diff --git a/src/vs/editor/common/model/textModelWithDecorations.ts b/src/vs/editor/common/model/textModelWithDecorations.ts index fc5da7ad380..9ed9c9a16e6 100644 --- a/src/vs/editor/common/model/textModelWithDecorations.ts +++ b/src/vs/editor/common/model/textModelWithDecorations.ts @@ -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 { diff --git a/src/vs/editor/common/viewModel/viewModelDecorations.ts b/src/vs/editor/common/viewModel/viewModelDecorations.ts index 9a5f7b38e76..59205a10171 100644 --- a/src/vs/editor/common/viewModel/viewModelDecorations.ts +++ b/src/vs/editor/common/viewModel/viewModelDecorations.ts @@ -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(); } diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index f1a7fcbf961..68cdaf1ccbc 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -282,8 +282,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel break; } case textModelEvents.TextModelEventType.ModelDecorationsChanged: { - const e = data; - this.decorations.onModelDecorationsChanged(e); + this.decorations.onModelDecorationsChanged(); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent()); break; } diff --git a/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts b/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts index bc0f080836d..42aaeb2fce0 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts @@ -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) => { diff --git a/src/vs/editor/test/common/model/modelDecorations.test.ts b/src/vs/editor/test/common/model/modelDecorations.test.ts index e8fd7a07654..84defed4ada 100644 --- a/src/vs/editor/test/common/model/modelDecorations.test.ts +++ b/src/vs/editor/test/common/model/modelDecorations.test.ts @@ -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 ')]); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 902254d86d2..96c24eb1b18 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -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[]; } /** diff --git a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts index 10fb1886dfd..55f5e51c46f 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts @@ -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(); 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 -- GitLab