Skip to content

Commit a4da791

Browse files
committed
Fixes microsoft#45908: Use idiomatic programming
1 parent c8d6102 commit a4da791

1 file changed

Lines changed: 9 additions & 38 deletions

File tree

src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -879,16 +879,12 @@ export class FilteredMatchesRenderer extends Disposable implements HiddenAreasPr
879879
public render(result: IFilterResult, allSettingsGroups: ISettingsGroup[]): void {
880880
const model = this.editor.getModel();
881881
this.hiddenAreas = [];
882-
this.editor.changeDecorations(changeAccessor => {
883-
this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, []);
884-
});
885882
if (result) {
886883
this.hiddenAreas = this.computeHiddenRanges(result.filteredGroups, result.allGroups, model);
887-
this.editor.changeDecorations(changeAccessor => {
888-
this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, result.matches.map(match => this.createDecoration(match, model)));
889-
});
884+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, result.matches.map(match => this.createDecoration(match, model)));
890885
} else {
891886
this.hiddenAreas = this.computeHiddenRanges(null, allSettingsGroups, model);
887+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
892888
}
893889
}
894890

@@ -920,11 +916,7 @@ export class FilteredMatchesRenderer extends Disposable implements HiddenAreasPr
920916
}
921917

922918
public dispose() {
923-
if (this.decorationIds) {
924-
this.decorationIds = this.editor.changeDecorations(changeAccessor => {
925-
return changeAccessor.deltaDecorations(this.decorationIds, []);
926-
});
927-
}
919+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
928920
super.dispose();
929921
}
930922
}
@@ -940,14 +932,7 @@ export class HighlightMatchesRenderer extends Disposable {
940932

941933
public render(matches: IRange[]): void {
942934
const model = this.editor.getModel();
943-
this.editor.changeDecorations(changeAccessor => {
944-
this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, []) || [];
945-
});
946-
if (matches.length) {
947-
this.editor.changeDecorations(changeAccessor => {
948-
this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, matches.map(match => this.createDecoration(match, model))) || [];
949-
});
950-
}
935+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, matches.map(match => this.createDecoration(match, model)));
951936
}
952937

953938
private static readonly _FIND_MATCH = ModelDecorationOptions.register({
@@ -963,11 +948,7 @@ export class HighlightMatchesRenderer extends Disposable {
963948
}
964949

965950
public dispose() {
966-
if (this.decorationIds) {
967-
this.decorationIds = this.editor.changeDecorations(changeAccessor => {
968-
return changeAccessor.deltaDecorations(this.decorationIds, []);
969-
}) || [];
970-
}
951+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
971952
super.dispose();
972953
}
973954
}
@@ -1383,7 +1364,7 @@ class UnsupportedSettingsRenderer extends Disposable {
13831364
} else {
13841365
this.markerService.remove('preferencesEditor', [this.settingsEditorModel.uri]);
13851366
}
1386-
this.editor.changeDecorations(changeAccessor => this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, ranges.map(range => this.createDecoration(range, this.editor.getModel()))));
1367+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, ranges.map(range => this.createDecoration(range, this.editor.getModel())));
13871368
}
13881369

13891370
private createDecoration(range: IRange, model: ITextModel): IModelDeltaDecoration {
@@ -1404,11 +1385,7 @@ class UnsupportedSettingsRenderer extends Disposable {
14041385

14051386
public dispose(): void {
14061387
this.markerService.remove('preferencesEditor', [this.settingsEditorModel.uri]);
1407-
if (this.decorationIds) {
1408-
this.decorationIds = this.editor.changeDecorations(changeAccessor => {
1409-
return changeAccessor.deltaDecorations(this.decorationIds, []);
1410-
});
1411-
}
1388+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
14121389
super.dispose();
14131390
}
14141391

@@ -1444,8 +1421,6 @@ class WorkspaceConfigurationRenderer extends Disposable {
14441421
this.associatedSettingsEditorModel = associatedSettingsEditorModel;
14451422
// Dim other configurations in workspace configuration file only in the context of Settings Editor
14461423
if (this.associatedSettingsEditorModel && this.workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE && this.workspaceSettingsEditorModel instanceof WorkspaceConfigurationEditorModel) {
1447-
this.editor.changeDecorations(changeAccessor => this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, []));
1448-
14491424
const ranges: IRange[] = [];
14501425
for (const settingsGroup of this.workspaceSettingsEditorModel.configurationGroups) {
14511426
for (const section of settingsGroup.sections) {
@@ -1461,7 +1436,7 @@ class WorkspaceConfigurationRenderer extends Disposable {
14611436
}
14621437
}
14631438
}
1464-
this.editor.changeDecorations(changeAccessor => this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, ranges.map(range => this.createDecoration(range, this.editor.getModel()))));
1439+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, ranges.map(range => this.createDecoration(range, this.editor.getModel())));
14651440
}
14661441
}
14671442

@@ -1478,11 +1453,7 @@ class WorkspaceConfigurationRenderer extends Disposable {
14781453
}
14791454

14801455
public dispose(): void {
1481-
if (this.decorationIds) {
1482-
this.decorationIds = this.editor.changeDecorations(changeAccessor => {
1483-
return changeAccessor.deltaDecorations(this.decorationIds, []);
1484-
});
1485-
}
1456+
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
14861457
super.dispose();
14871458
}
14881459
}

0 commit comments

Comments
 (0)