提交 16294b41 编写于 作者: A Alex Dima

Do not emit events when deltaDecorations is a no-op

上级 ba81d4af
......@@ -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();
......
......@@ -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', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册