Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve editor preference dendrification #11711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions packages/monaco/src/browser/monaco-editor-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,17 @@ export class MonacoEditorProvider {
}

/** @deprecated always pass a language as an overrideIdentifier */
protected createOptions(prefixes: string[], uri: string): { [name: string]: any };
protected createOptions(prefixes: string[], uri: string, overrideIdentifier: string): { [name: string]: any };
protected createOptions(prefixes: string[], uri: string, overrideIdentifier?: string): { [name: string]: any } {
protected createOptions(prefixes: string[], uri: string): Record<string, any>;
protected createOptions(prefixes: string[], uri: string, overrideIdentifier: string): Record<string, any>;
protected createOptions(prefixes: string[], uri: string, overrideIdentifier?: string): Record<string, any> {
const flat: Record<string, any> = {};
for (const preferenceName of Object.keys(this.editorPreferences)) {
flat[preferenceName] = (<any>this.editorPreferences).get({ preferenceName, overrideIdentifier }, undefined, uri);
}
return Object.entries(flat).reduce((tree, [preferenceName, value]) => this.setOption(preferenceName, deepClone(value), prefixes, tree), {});
}

protected setOption(preferenceName: string, value: any, prefixes: string[], options: { [name: string]: any } = {}): {
protected setOption(preferenceName: string, value: any, prefixes: string[], options: Record<string, any> = {}): {
[name: string]: any;
} {
const optionName = this.toOptionName(preferenceName, prefixes);
Expand All @@ -376,16 +376,19 @@ export class MonacoEditorProvider {
}
return preferenceName;
}
protected doSetOption(obj: { [name: string]: any }, value: any, names: string[], idx: number = 0): void {
const name = names[idx];
if (!obj[name]) {
if (names.length > (idx + 1)) {
obj[name] = {};
this.doSetOption(obj[name], value, names, (idx + 1));
protected doSetOption(obj: Record<string, any>, value: any, names: string[]): void {
for (let i = 0; i < names.length - 1; i++) {
const name = names[i];
if (obj[name] === undefined) {
obj = obj[name] = {};
} else if (typeof obj[name] !== 'object' || obj[name] === null) { // eslint-disable-line no-null/no-null
console.warn(`Preference (diff)editor.${names.join('.')} conflicts with another preference name.`);
obj = obj[name] = {};
} else {
obj[name] = value;
obj = obj[name];
}
}
obj[names[names.length - 1]] = value;
}

getDiffNavigator(editor: TextEditor): DiffNavigator {
Expand Down
1 change: 1 addition & 0 deletions packages/monaco/src/browser/monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
lightbulb: { enabled: true },
fixedOverflowWidgets: true,
scrollbar: {
...options?.scrollbar,
useShadows: false,
verticalHasArrows: false,
horizontalHasArrows: false,
Expand Down