未验证 提交 616afa93 编写于 作者: R Rob Lourens 提交者: GitHub

Merge pull request #106038 from microsoft/lszomoru/color-setting

Settings - Add string validator for color-hex format
...@@ -324,8 +324,6 @@ configurationRegistry.registerConfiguration({ ...@@ -324,8 +324,6 @@ configurationRegistry.registerConfiguration({
type: 'string', type: 'string',
format: 'color-hex', format: 'color-hex',
default: '#FF0000', 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.") description: nls.localize('screencastMode.mouseIndicatorColor', "Controls the color in hex (#RGB, #RGBA, #RRGGBB or #RRGGBBAA) of the mouse indicator in screencast mode.")
}, },
'screencastMode.mouseIndicatorSize': { 'screencastMode.mouseIndicatorSize': {
......
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * 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 { JSONSchemaType } from 'vs/base/common/jsonSchema';
import { Color } from 'vs/base/common/color';
import { isArray } from 'vs/base/common/types'; import { isArray } from 'vs/base/common/types';
import * as nls from 'vs/nls';
import { IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry'; import { IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry';
type Validator<T> = { enabled: boolean, isValid: (value: T) => boolean; message: string }; type Validator<T> = { enabled: boolean, isValid: (value: T) => boolean; message: string };
...@@ -111,6 +112,11 @@ function getStringValidators(prop: IConfigurationPropertySchema) { ...@@ -111,6 +112,11 @@ function getStringValidators(prop: IConfigurationPropertySchema) {
isValid: ((value: string) => patternRegex!.test(value)), isValid: ((value: string) => patternRegex!.test(value)),
message: prop.patternErrorMessage || nls.localize('validations.regex', "Value must match regex `{0}`.", prop.pattern) 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); ].filter(validation => validation.enabled);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册