Skip to content

Commit

Permalink
Improve editor preference dendrification (#11711)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work authored Sep 30, 2022
1 parent fd845f6 commit d3f6359
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
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

0 comments on commit d3f6359

Please sign in to comment.