From 2445428308d74f1eedf73715809dca2d37e21c6d Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 3 Sep 2020 14:14:42 +0200 Subject: [PATCH] Add string validator for color-hex format --- src/vs/workbench/browser/actions/developerActions.ts | 2 -- .../services/preferences/common/preferencesValidation.ts | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/browser/actions/developerActions.ts b/src/vs/workbench/browser/actions/developerActions.ts index 5e7e9499f0723..3820e9c8ac8e2 100644 --- a/src/vs/workbench/browser/actions/developerActions.ts +++ b/src/vs/workbench/browser/actions/developerActions.ts @@ -324,8 +324,6 @@ configurationRegistry.registerConfiguration({ type: 'string', format: 'color-hex', default: '#FF0000', - minLength: 4, - maxLength: 9, description: nls.localize('screencastMode.mouseIndicatorColor', "Controls the color in hex (#RGB, #RGBA, #RRGGBB or #RRGGBBAA) of the mouse indicator in screencast mode.") }, 'screencastMode.mouseIndicatorSize': { diff --git a/src/vs/workbench/services/preferences/common/preferencesValidation.ts b/src/vs/workbench/services/preferences/common/preferencesValidation.ts index 6a20533359693..40b916d16aeaf 100644 --- a/src/vs/workbench/services/preferences/common/preferencesValidation.ts +++ b/src/vs/workbench/services/preferences/common/preferencesValidation.ts @@ -3,9 +3,10 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as nls from 'vs/nls'; import { JSONSchemaType } from 'vs/base/common/jsonSchema'; +import { Color } from 'vs/base/common/color'; import { isArray } from 'vs/base/common/types'; -import * as nls from 'vs/nls'; import { IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry'; type Validator = { enabled: boolean, isValid: (value: T) => boolean; message: string }; @@ -111,6 +112,11 @@ function getStringValidators(prop: IConfigurationPropertySchema) { isValid: ((value: string) => patternRegex!.test(value)), message: prop.patternErrorMessage || nls.localize('validations.regex', "Value must match regex `{0}`.", prop.pattern) }, + { + enabled: prop.format === 'color-hex', + isValid: ((value: string) => Color.Format.CSS.parseHex(value)), + message: nls.localize('validations.colorFormat', "Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA.") + } ].filter(validation => validation.enabled); }