allowedCharacters: string -> allowedCharacters: Record<string, bool>

上级 093aa3c4
......@@ -3312,9 +3312,9 @@ export interface IUnicodeHighlightOptions {
ambiguousCharacters?: boolean;
includeComments?: boolean | InUntrustedWorkspace;
/**
* A list of allowed code points in a single string.
* A map of allowed characters (true: allowed).
*/
allowedCharacters?: string;
allowedCharacters?: Record<string, true>;
}
/**
......@@ -3340,7 +3340,7 @@ class UnicodeHighlight extends BaseEditorOption<EditorOption.unicodeHighlighting
invisibleCharacters: true,
ambiguousCharacters: true,
includeComments: inUntrustedWorkspace,
allowedCharacters: '',
allowedCharacters: {},
};
super(
......@@ -3374,14 +3374,34 @@ class UnicodeHighlight extends BaseEditorOption<EditorOption.unicodeHighlighting
},
[unicodeHighlightConfigKeys.allowedCharacters]: {
restricted: true,
type: 'string',
type: 'object',
default: defaults.allowedCharacters,
description: nls.localize('unicodeHighlight.allowedCharacters', "Defines allowed characters that are not being highlighted.")
description: nls.localize('unicodeHighlight.allowedCharacters', "Defines allowed characters that are not being highlighted."),
additionalProperties: {
type: 'boolean'
}
},
}
);
}
public override applyUpdate(value: Required<Readonly<IUnicodeHighlightOptions>>, update: Required<Readonly<IUnicodeHighlightOptions>>): ApplyUpdateResult<Required<Readonly<IUnicodeHighlightOptions>>> {
let didChange = false;
if (update.allowedCharacters) {
// Treat allowedCharacters atomically
if (!objects.equals(value.allowedCharacters, update.allowedCharacters)) {
value = { ...value, allowedCharacters: update.allowedCharacters };
didChange = true;
}
}
const result = super.applyUpdate(value, update);
if (didChange) {
return new ApplyUpdateResult(result.newValue, true);
}
return result;
}
public validate(_input: any): InternalUnicodeHighlightOptions {
if (!_input || typeof _input !== 'object') {
return this.defaultValue;
......@@ -3392,16 +3412,22 @@ class UnicodeHighlight extends BaseEditorOption<EditorOption.unicodeHighlighting
invisibleCharacters: boolean(input.invisibleCharacters, this.defaultValue.invisibleCharacters),
ambiguousCharacters: boolean(input.ambiguousCharacters, this.defaultValue.ambiguousCharacters),
includeComments: primitiveSet<boolean | InUntrustedWorkspace>(input.includeComments, inUntrustedWorkspace, [true, false, inUntrustedWorkspace]),
allowedCharacters: string(input.allowedCharacters, ''),
allowedCharacters: this.validateAllowedCharacters(_input.allowedCharacters, this.defaultValue.allowedCharacters),
};
}
}
function string(value: unknown, defaultValue: string): string {
if (typeof value !== 'string') {
return defaultValue;
private validateAllowedCharacters(map: unknown, defaultValue: Record<string, true>): Record<string, true> {
if ((typeof map !== 'object') || !map) {
return defaultValue;
}
const result: Record<string, true> = {};
for (const [key, value] of Object.entries(map)) {
if (value === true) {
result[key] = true;
}
}
return result;
}
return value;
}
//#endregion
......
......@@ -160,7 +160,7 @@ export class UnicodeHighlighter extends Disposable implements IEditorContributio
ambiguousCharacters: options.ambiguousCharacters,
invisibleCharacters: options.invisibleCharacters,
includeComments: options.includeComments,
allowedCodePoints: Array.from(options.allowedCharacters).map(c => c.codePointAt(0)!),
allowedCodePoints: Object.keys(options.allowedCharacters).map(c => c.codePointAt(0)!),
};
if (this._editorWorkerService.canComputeUnicodeHighlights(this._editor.getModel().uri)) {
......@@ -191,7 +191,7 @@ function resolveOptions(trusted: boolean, options: InternalUnicodeHighlightOptio
ambiguousCharacters: options.ambiguousCharacters,
invisibleCharacters: options.invisibleCharacters,
includeComments: options.includeComments === inUntrustedWorkspace ? !trusted : options.includeComments,
allowedCharacters: options.allowedCharacters ?? [],
allowedCharacters: options.allowedCharacters ?? {},
};
}
......@@ -640,18 +640,7 @@ export class ShowExcludeOptions extends EditorAction {
const options: ExtendedOptions[] = [
{
label: getExcludeCharFromBeingHighlightedLabel(codePoint),
run: async () => {
const existingValue = configurationService.getValue(unicodeHighlightConfigKeys.allowedCharacters);
let value: string;
if (typeof existingValue === 'string') {
value = existingValue;
} else {
value = '';
}
value += char;
await configurationService.updateValue(unicodeHighlightConfigKeys.allowedCharacters, value, ConfigurationTarget.USER);
}
run: () => excludeCharFromBeingHighlighted(configurationService, [codePoint])
},
];
......@@ -681,6 +670,23 @@ export class ShowExcludeOptions extends EditorAction {
}
}
async function excludeCharFromBeingHighlighted(configurationService: IConfigurationService, charCodes: number[]) {
const existingValue = configurationService.getValue(unicodeHighlightConfigKeys.allowedCharacters);
let value: Record<string, boolean>;
if ((typeof existingValue === 'object') && existingValue) {
value = existingValue as any;
} else {
value = {};
}
for (const charCode of charCodes) {
value[String.fromCodePoint(charCode)] = true;
}
await configurationService.updateValue(unicodeHighlightConfigKeys.allowedCharacters, value, ConfigurationTarget.USER);
}
function expectNever(value: never) {
throw new Error(`Unexpected value: ${value}`);
}
......
......@@ -3884,9 +3884,9 @@ declare namespace monaco.editor {
ambiguousCharacters?: boolean;
includeComments?: boolean | InUntrustedWorkspace;
/**
* A list of allowed code points in a single string.
* A map of allowed characters (true: allowed).
*/
allowedCharacters?: string;
allowedCharacters?: Record<string, true>;
}
export interface IInlineSuggestOptions {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册