Skip to content

Commit d193d82

Browse files
authored
"default" colorCustomization doesn't get unset when removing setting override (microsoft#218362)
1 parent b4eb545 commit d193d82

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/vs/workbench/services/themes/common/colorThemeData.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export type TokenStyleDefinitions = { [P in keyof TokenStyleData]?: TokenStyleDe
4545

4646
export type TextMateThemingRuleDefinitions = { [P in keyof TokenStyleData]?: ITextMateThemingRule | undefined; } & { scope?: ProbeScope };
4747

48+
interface IColorOrDefaultMap {
49+
[id: string]: Color | typeof DEFAULT_COLOR_CONFIG_VALUE;
50+
}
51+
4852
export class ColorThemeData implements IWorkbenchColorTheme {
4953

5054
static readonly STORAGE_KEY = 'colorThemeData';
@@ -65,7 +69,7 @@ export class ColorThemeData implements IWorkbenchColorTheme {
6569
private themeTokenColors: ITextMateThemingRule[] = [];
6670
private customTokenColors: ITextMateThemingRule[] = [];
6771
private colorMap: IColorMap = {};
68-
private customColorMap: IColorMap = {};
72+
private customColorMap: IColorOrDefaultMap = {};
6973

7074
private semanticTokenRules: SemanticTokenRule[] = [];
7175
private customSemanticTokenRules: SemanticTokenRule[] = [];
@@ -132,15 +136,20 @@ export class ColorThemeData implements IWorkbenchColorTheme {
132136
}
133137

134138
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color | undefined {
135-
let color: Color | undefined = this.customColorMap[colorId];
136-
if (color) {
137-
return color;
139+
const customColor = this.customColorMap[colorId];
140+
if (customColor instanceof Color) {
141+
return customColor;
142+
}
143+
if (customColor === undefined) { /* !== DEFAULT_COLOR_CONFIG_VALUE */
144+
const color = this.colorMap[colorId];
145+
if (color !== undefined) {
146+
return color;
147+
}
138148
}
139-
color = this.colorMap[colorId];
140-
if (useDefault !== false && types.isUndefined(color)) {
141-
color = this.getDefault(colorId);
149+
if (useDefault !== false) {
150+
return this.getDefault(colorId);
142151
}
143-
return color;
152+
return undefined;
144153
}
145154

146155
private getTokenStyle(type: string, modifiers: string[], language: string, useDefault = true, definitions: TokenStyleDefinitions = {}): TokenStyle | undefined {
@@ -346,7 +355,11 @@ export class ColorThemeData implements IWorkbenchColorTheme {
346355
}
347356

348357
public defines(colorId: ColorIdentifier): boolean {
349-
return this.customColorMap.hasOwnProperty(colorId) || this.colorMap.hasOwnProperty(colorId);
358+
const customColor = this.customColorMap[colorId];
359+
if (customColor instanceof Color) {
360+
return true;
361+
}
362+
return customColor === undefined /* !== DEFAULT_COLOR_CONFIG_VALUE */ && this.colorMap.hasOwnProperty(colorId);
350363
}
351364

352365
public setCustomizations(settings: ThemeConfiguration) {
@@ -373,7 +386,7 @@ export class ColorThemeData implements IWorkbenchColorTheme {
373386
for (const id in colors) {
374387
const colorVal = colors[id];
375388
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) {
376-
delete this.colorMap[id];
389+
this.customColorMap[id] = DEFAULT_COLOR_CONFIG_VALUE;
377390
} else if (typeof colorVal === 'string') {
378391
this.customColorMap[id] = Color.fromHex(colorVal);
379392
}
@@ -719,9 +732,9 @@ async function _loadColorTheme(extensionResourceLoaderService: IExtensionResourc
719732
// new JSON color themes format
720733
for (const colorId in colors) {
721734
const colorVal = colors[colorId];
722-
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) {
735+
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) { // ignore colors that are set to to default
723736
delete result.colors[colorId];
724-
} else if (typeof colorVal === 'string') { // ignore colors that are null
737+
} else if (typeof colorVal === 'string') {
725738
result.colors[colorId] = Color.fromHex(colors[colorId]);
726739
}
727740
}

0 commit comments

Comments
 (0)