Skip to content

Commit c7bb864

Browse files
authored
Avoid editor.deltaDecorations (microsoft#153463)
Fixes microsoft#153215: Avoid `editor.deltaDecorations`
1 parent cf0cb66 commit c7bb864

File tree

10 files changed

+40
-19
lines changed

10 files changed

+40
-19
lines changed

src/vs/editor/browser/editorBrowser.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,20 +856,25 @@ export interface ICodeEditor extends editorCommon.IEditor {
856856
*/
857857
deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];
858858

859+
/**
860+
* Remove previously added decorations.
861+
*/
862+
removeDecorations(decorationIds: string[]): void;
863+
859864
/**
860865
* @internal
861866
*/
862-
setDecorations(description: string, decorationTypeKey: string, ranges: editorCommon.IDecorationOptions[]): void;
867+
setDecorationsByType(description: string, decorationTypeKey: string, ranges: editorCommon.IDecorationOptions[]): void;
863868

864869
/**
865870
* @internal
866871
*/
867-
setDecorationsFast(decorationTypeKey: string, ranges: IRange[]): void;
872+
setDecorationsByTypeFast(decorationTypeKey: string, ranges: IRange[]): void;
868873

869874
/**
870875
* @internal
871876
*/
872-
removeDecorations(decorationTypeKey: string): void;
877+
removeDecorationsByType(decorationTypeKey: string): void;
873878

874879
/**
875880
* Get the layout info for the editor.

src/vs/editor/browser/services/abstractCodeEditorService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export abstract class AbstractCodeEditorService extends Disposable implements IC
161161
if (provider.refCount <= 0) {
162162
this._decorationOptionProviders.delete(key);
163163
provider.dispose();
164-
this.listCodeEditors().forEach((ed) => ed.removeDecorations(key));
164+
this.listCodeEditors().forEach((ed) => ed.removeDecorationsByType(key));
165165
}
166166
}
167167
}

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,17 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
12981298
return this._modelData.model.deltaDecorations(oldDecorations, newDecorations, this._id);
12991299
}
13001300

1301-
public setDecorations(description: string, decorationTypeKey: string, decorationOptions: editorCommon.IDecorationOptions[]): void {
1301+
public removeDecorations(decorationIds: string[]): void {
1302+
if (!this._modelData || decorationIds.length === 0) {
1303+
return;
1304+
}
1305+
1306+
this._modelData.model.changeDecorations((changeAccessor) => {
1307+
changeAccessor.deltaDecorations(decorationIds, []);
1308+
});
1309+
}
1310+
1311+
public setDecorationsByType(description: string, decorationTypeKey: string, decorationOptions: editorCommon.IDecorationOptions[]): void {
13021312

13031313
const newDecorationsSubTypes: { [key: string]: boolean } = {};
13041314
const oldDecorationsSubTypes = this._decorationTypeSubtypes[decorationTypeKey] || {};
@@ -1340,7 +1350,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
13401350
this._decorationTypeKeysToIds[decorationTypeKey] = this.deltaDecorations(oldDecorationsIds, newModelDecorations);
13411351
}
13421352

1343-
public setDecorationsFast(decorationTypeKey: string, ranges: IRange[]): void {
1353+
public setDecorationsByTypeFast(decorationTypeKey: string, ranges: IRange[]): void {
13441354

13451355
// remove decoration sub types that are no longer used, deregister decoration type if necessary
13461356
const oldDecorationsSubTypes = this._decorationTypeSubtypes[decorationTypeKey] || {};
@@ -1360,7 +1370,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
13601370
this._decorationTypeKeysToIds[decorationTypeKey] = this.deltaDecorations(oldDecorationsIds, newModelDecorations);
13611371
}
13621372

1363-
public removeDecorations(decorationTypeKey: string): void {
1373+
public removeDecorationsByType(decorationTypeKey: string): void {
13641374
// remove decorations for type and sub type
13651375
const oldDecorationsIds = this._decorationTypeKeysToIds[decorationTypeKey];
13661376
if (oldDecorationsIds) {

src/vs/editor/contrib/gotoSymbol/browser/peek/referencesWidget.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ class DecorationsManager implements IDisposable {
100100
newDecorationsActualIndex.push(i);
101101
}
102102

103-
const decorations = this._editor.deltaDecorations([], newDecorations);
104-
for (let i = 0; i < decorations.length; i++) {
105-
this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]);
106-
}
103+
this._editor.changeDecorations((changeAccessor) => {
104+
const decorations = changeAccessor.deltaDecorations([], newDecorations);
105+
for (let i = 0; i < decorations.length; i++) {
106+
this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]);
107+
}
108+
});
107109
}
108110

109111
private _onDecorationChanged(): void {
@@ -151,11 +153,11 @@ class DecorationsManager implements IDisposable {
151153
for (let i = 0, len = toRemove.length; i < len; i++) {
152154
this._decorations.delete(toRemove[i]);
153155
}
154-
this._editor.deltaDecorations(toRemove, []);
156+
this._editor.removeDecorations(toRemove);
155157
}
156158

157159
removeDecorations(): void {
158-
this._editor.deltaDecorations([...this._decorations.keys()], []);
160+
this._editor.removeDecorations([...this._decorations.keys()]);
159161
this._decorations.clear();
160162
}
161163
}

src/vs/monaco.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5316,6 +5316,10 @@ declare namespace monaco.editor {
53165316
* @see {@link ITextModel.deltaDecorations}
53175317
*/
53185318
deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];
5319+
/**
5320+
* Remove previously added decorations.
5321+
*/
5322+
removeDecorations(decorationIds: string[]): void;
53195323
/**
53205324
* Get the layout info for the editor.
53215325
*/

src/vs/workbench/api/browser/mainThreadEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class MainThreadTextEditor {
415415
if (!this._codeEditor) {
416416
return;
417417
}
418-
this._codeEditor.setDecorations('exthost-api', key, ranges);
418+
this._codeEditor.setDecorationsByType('exthost-api', key, ranges);
419419
}
420420

421421
public setDecorationsFast(key: string, _ranges: number[]): void {
@@ -426,7 +426,7 @@ export class MainThreadTextEditor {
426426
for (let i = 0, len = Math.floor(_ranges.length / 4); i < len; i++) {
427427
ranges[i] = new Range(_ranges[4 * i], _ranges[4 * i + 1], _ranges[4 * i + 2], _ranges[4 * i + 3]);
428428
}
429-
this._codeEditor.setDecorationsFast(key, ranges);
429+
this._codeEditor.setDecorationsByTypeFast(key, ranges);
430430
}
431431

432432
public revealRange(range: IRange, revealType: TextEditorRevealType): void {

src/vs/workbench/contrib/comments/browser/commentReply.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
191191
}
192192
}];
193193

194-
this.commentEditor.setDecorations('review-zone-widget', COMMENTEDITOR_DECORATION_KEY, decorations);
194+
this.commentEditor.setDecorationsByType('review-zone-widget', COMMENTEDITOR_DECORATION_KEY, decorations);
195195
}
196196
}
197197

src/vs/workbench/contrib/debug/browser/breakpointWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
238238
const setDecorations = () => {
239239
const value = this.input.getModel().getValue();
240240
const decorations = !!value ? [] : createDecorations(this.themeService.getColorTheme(), this.placeholder);
241-
this.input.setDecorations('breakpoint-widget', DECORATION_KEY, decorations);
241+
this.input.setDecorationsByType('breakpoint-widget', DECORATION_KEY, decorations);
242242
};
243243
this.input.getModel().onDidChangeContent(() => setDecorations());
244244
this.themeService.onDidColorThemeChange(() => setDecorations());

src/vs/workbench/contrib/debug/browser/repl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
718718
});
719719
}
720720

721-
this.replInput.setDecorations('repl-decoration', DECORATION_KEY, decorations);
721+
this.replInput.setDecorationsByType('repl-decoration', DECORATION_KEY, decorations);
722722
}
723723

724724
override saveState(): void {

src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ export class InteractiveEditor extends EditorPane {
620620
});
621621
}
622622

623-
this.#codeEditorWidget.setDecorations('interactive-decoration', DECORATION_KEY, decorations);
623+
this.#codeEditorWidget.setDecorationsByType('interactive-decoration', DECORATION_KEY, decorations);
624624
}
625625

626626
override focus() {

0 commit comments

Comments
 (0)