diff --git a/src/vs/editor/common/model/textModelWithDecorations.ts b/src/vs/editor/common/model/textModelWithDecorations.ts index 0418026b5060c3f63dbcec3bf4335bb36b5cdbe3..45fa84e9003c52b64b9c678494730fc142e87d9c 100644 --- a/src/vs/editor/common/model/textModelWithDecorations.ts +++ b/src/vs/editor/common/model/textModelWithDecorations.ts @@ -166,6 +166,10 @@ export class TextModelWithDecorations extends TextModelWithTokens implements edi this._deltaDecorationsImpl(ownerId, [id], []); }, deltaDecorations: (oldDecorations: string[], newDecorations: editorCommon.IModelDeltaDecoration[]): string[] => { + if (oldDecorations.length === 0 && newDecorations.length === 0) { + // nothing to do + return []; + } this._currentDecorationsTrackerDidChange = true; return this._deltaDecorationsImpl(ownerId, oldDecorations, newDecorations); } @@ -189,6 +193,10 @@ export class TextModelWithDecorations extends TextModelWithTokens implements edi if (!oldDecorations) { oldDecorations = []; } + if (oldDecorations.length === 0 && newDecorations.length === 0) { + // nothing to do + return []; + } try { this._eventEmitter.beginDeferredEmit(); diff --git a/src/vs/editor/test/common/model/modelDecorations.test.ts b/src/vs/editor/test/common/model/modelDecorations.test.ts index b4485b014de6eaeeb142cc74259f733fcf617757..23c02e75b0973c45941298c7d269e7d1f4febeec 100644 --- a/src/vs/editor/test/common/model/modelDecorations.test.ts +++ b/src/vs/editor/test/common/model/modelDecorations.test.ts @@ -249,6 +249,21 @@ suite('Editor Model - Model Decorations', () => { assert.equal(listenerCalled, 1, 'listener called'); }); + test('decorations do not emit event on no-op deltaDecorations', () => { + let listenerCalled = 0; + + thisModel.onDidChangeDecorations((e) => { + listenerCalled++; + }); + + thisModel.deltaDecorations([], []); + thisModel.changeDecorations((accessor) => { + accessor.deltaDecorations([], []); + }); + + assert.equal(listenerCalled, 0, 'listener not called'); + }); + // --------- editing text & effects on decorations test('decorations are updated when inserting one line text before it', () => {