Skip to content

Commit 28cbfce

Browse files
SimonSiefkeaeschli
andauthored
feature: allow unsetting color theme values in settings (#213512)
* allow null value * allow unsetting color * undo change * delete color * undo changes * remove unused code * unset right map * add function to create nullable color schema * use nullable schema * undo change * fix nullable object * use default value * update both schemas on timeout * simplifications & polish --------- Co-authored-by: Martin Aeschlimann
1 parent d7eb0f1 commit 28cbfce

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/vs/platform/theme/common/colorUtils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
1111
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
1212
import * as platform from 'vs/platform/registry/common/platform';
1313
import { IColorTheme } from 'vs/platform/theme/common/themeService';
14+
import * as nls from 'vs/nls';
1415

1516
// ------ API types
1617

@@ -79,6 +80,8 @@ export const Extensions = {
7980
ColorContribution: 'base.contributions.colors'
8081
};
8182

83+
export const DEFAULT_COLOR_CONFIG_VALUE = 'default';
84+
8285
export interface IColorRegistry {
8386

8487
readonly onDidChangeSchema: Event<void>;
@@ -141,9 +144,14 @@ class ColorRegistry implements IColorRegistry {
141144
}
142145
if (needsTransparency) {
143146
propertySchema.pattern = '^#(?:(?[0-9a-fA-f]{3}[0-9a-eA-E])|(?:[0-9a-fA-F]{6}(?:(?![fF]{2})(?:[0-9a-fA-F]{2}))))?$';
144-
propertySchema.patternErrorMessage = 'This color must be transparent or it will obscure content';
147+
propertySchema.patternErrorMessage = nls.localize('transparecyRequired', 'This color must be transparent or it will obscure content');
145148
}
146-
this.colorSchema.properties[id] = propertySchema;
149+
this.colorSchema.properties[id] = {
150+
oneOf: [
151+
propertySchema,
152+
{ type: 'string', const: DEFAULT_COLOR_CONFIG_VALUE, description: nls.localize('useDefault', 'Use the default color.') }
153+
]
154+
};
147155
this.colorReferenceSchema.enum.push(id);
148156
this.colorReferenceSchema.enumDescriptions.push(description);
149157

@@ -319,6 +327,7 @@ const schemaRegistry = platform.Registry.as(JSONExten
319327
schemaRegistry.registerSchema(workbenchColorsSchemaId, colorRegistry.getColorSchema());
320328

321329
const delayer = new RunOnceScheduler(() => schemaRegistry.notifySchemaChanged(workbenchColorsSchemaId), 200);
330+
322331
colorRegistry.onDidChangeSchema(() => {
323332
if (!delayer.isScheduled()) {
324333
delayer.schedule();

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { convertSettings } from 'vs/workbench/services/themes/common/themeCompat
1111
import * as nls from 'vs/nls';
1212
import * as types from 'vs/base/common/types';
1313
import * as resources from 'vs/base/common/resources';
14-
import { Extensions as ColorRegistryExtensions, IColorRegistry, ColorIdentifier, editorBackground, editorForeground } from 'vs/platform/theme/common/colorRegistry';
14+
import { Extensions as ColorRegistryExtensions, IColorRegistry, ColorIdentifier, editorBackground, editorForeground, DEFAULT_COLOR_CONFIG_VALUE } from 'vs/platform/theme/common/colorRegistry';
1515
import { ITokenStyle, getThemeTypeSelector } from 'vs/platform/theme/common/themeService';
1616
import { Registry } from 'vs/platform/registry/common/platform';
1717
import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
@@ -372,7 +372,9 @@ export class ColorThemeData implements IWorkbenchColorTheme {
372372
private overwriteCustomColors(colors: IColorCustomizations) {
373373
for (const id in colors) {
374374
const colorVal = colors[id];
375-
if (typeof colorVal === 'string') {
375+
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) {
376+
delete this.colorMap[id];
377+
} else if (typeof colorVal === 'string') {
376378
this.customColorMap[id] = Color.fromHex(colorVal);
377379
}
378380
}
@@ -716,8 +718,10 @@ async function _loadColorTheme(extensionResourceLoaderService: IExtensionResourc
716718
}
717719
// new JSON color themes format
718720
for (const colorId in colors) {
719-
const colorHex = colors[colorId];
720-
if (typeof colorHex === 'string') { // ignore colors tht are null
721+
const colorVal = colors[colorId];
722+
if (colorVal === DEFAULT_COLOR_CONFIG_VALUE) {
723+
delete result.colors[colorId];
724+
} else if (typeof colorVal === 'string') { // ignore colors that are null
721725
result.colors[colorId] = Color.fromHex(colors[colorId]);
722726
}
723727
}

0 commit comments

Comments
 (0)