Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 13c79ce

Browse files
committed
Allow to influence monaco editor configuration directly in both modes
1 parent 6bbc099 commit 13c79ce

File tree

5 files changed

+30
-50
lines changed

5 files changed

+30
-50
lines changed

Diff for: packages/monaco-editor-wrapper/src/editorAppBase.ts

+24-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export type EditorAppConfigBase = ModelUpdate & {
1919
domReadOnly?: boolean;
2020
readOnly?: boolean;
2121
awaitExtensionReadiness?: Array<() => Promise<void>>;
22+
overrideAutomaticLayout?: boolean;
23+
editorOptions?: editor.IStandaloneEditorConstructionOptions;
24+
diffEditorOptions?: editor.IStandaloneDiffEditorConstructionOptions;
2225
}
2326

2427
export enum ModelUpdateType {
@@ -49,7 +52,7 @@ export abstract class EditorAppBase {
4952
}
5053

5154
protected buildConfig(userAppConfig: EditorAppConfigBase): EditorAppConfigBase {
52-
return {
55+
const config: EditorAppConfigBase = {
5356
$type: userAppConfig.$type,
5457
languageId: userAppConfig.languageId,
5558
code: userAppConfig.code ?? '',
@@ -59,8 +62,18 @@ export abstract class EditorAppBase {
5962
codeOriginalUri: userAppConfig.codeOriginalUri ?? undefined,
6063
readOnly: userAppConfig.readOnly ?? false,
6164
domReadOnly: userAppConfig.domReadOnly ?? false,
62-
awaitExtensionReadiness: userAppConfig.awaitExtensionReadiness ?? undefined
65+
overrideAutomaticLayout: userAppConfig.overrideAutomaticLayout ?? true,
66+
awaitExtensionReadiness: userAppConfig.awaitExtensionReadiness ?? undefined,
6367
};
68+
config.editorOptions = {
69+
...userAppConfig.editorOptions,
70+
automaticLayout: userAppConfig.overrideAutomaticLayout ?? true
71+
};
72+
config.diffEditorOptions = {
73+
...userAppConfig.diffEditorOptions,
74+
automaticLayout: userAppConfig.overrideAutomaticLayout ?? true
75+
};
76+
return config;
6477
}
6578

6679
haveEditor() {
@@ -75,14 +88,14 @@ export abstract class EditorAppBase {
7588
return this.diffEditor;
7689
}
7790

78-
protected async createEditor(container: HTMLElement, editorOptions?: editor.IStandaloneEditorConstructionOptions): Promise<void> {
79-
this.editor = createConfiguredEditor(container, editorOptions);
80-
await this.updateEditorModel();
81-
}
82-
83-
protected async createDiffEditor(container: HTMLElement, diffEditorOptions?: editor.IStandaloneDiffEditorConstructionOptions): Promise<void> {
84-
this.diffEditor = createConfiguredDiffEditor(container, diffEditorOptions);
85-
await this.updateDiffEditorModel();
91+
async createEditors(container: HTMLElement): Promise<void> {
92+
if (this.getConfig().useDiffEditor) {
93+
this.diffEditor = createConfiguredDiffEditor(container, this.getConfig().diffEditorOptions);
94+
await this.updateDiffEditorModel();
95+
} else {
96+
this.editor = createConfiguredEditor(container, this.getConfig().editorOptions);
97+
await this.updateEditorModel();
98+
}
8699
}
87100

88101
protected disposeEditor() {
@@ -231,8 +244,7 @@ export abstract class EditorAppBase {
231244
}
232245

233246
abstract init(): Promise<void>;
234-
abstract specifyService(): editor.IEditorOverrideServices;
235-
abstract createEditors(container: HTMLElement): Promise<void>;
247+
abstract specifyServices(): editor.IEditorOverrideServices;
236248
abstract getConfig(): EditorAppConfigBase;
237249
abstract disposeApp(): void;
238250
abstract isAppConfigDifferent(orgConfig: EditorAppConfigBase, config: EditorAppConfigBase, includeModelData: boolean): boolean;

Diff for: packages/monaco-editor-wrapper/src/editorAppClassic.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { Logger } from './logger.js';
55

66
export type EditorAppConfigClassic = EditorAppConfigBase & {
77
$type: 'classic';
8-
automaticLayout?: boolean;
98
theme?: editor.BuiltinTheme | string;
10-
editorOptions?: editor.IStandaloneEditorConstructionOptions;
11-
diffEditorOptions?: editor.IStandaloneDiffEditorConstructionOptions;
129
languageExtensionConfig?: languages.ILanguageExtensionPoint;
1310
languageDef?: languages.IMonarchLanguage;
1411
themeData?: editor.IStandaloneThemeData;
@@ -29,15 +26,6 @@ export class EditorAppClassic extends EditorAppBase {
2926
this.config = this.buildConfig(userAppConfig) as EditorAppConfigClassic;
3027
// default to vs-light
3128
this.config.theme = userAppConfig.theme ?? 'vs-light';
32-
// default to true
33-
this.config.automaticLayout = userAppConfig.automaticLayout ?? true;
34-
35-
this.config.editorOptions = userAppConfig.editorOptions ?? {};
36-
this.config.editorOptions.automaticLayout = userAppConfig.automaticLayout ?? true;
37-
38-
this.config.diffEditorOptions = userAppConfig.diffEditorOptions ?? {};
39-
this.config.diffEditorOptions.automaticLayout = userAppConfig.automaticLayout ?? true;
40-
4129
this.config.languageExtensionConfig = userAppConfig.languageExtensionConfig ?? undefined;
4230
this.config.languageDef = userAppConfig.languageDef ?? undefined;
4331
this.config.themeData = userAppConfig.themeData ?? undefined;
@@ -47,18 +35,10 @@ export class EditorAppClassic extends EditorAppBase {
4735
return this.config;
4836
}
4937

50-
override specifyService(): editor.IEditorOverrideServices {
38+
override specifyServices(): editor.IEditorOverrideServices {
5139
return {};
5240
}
5341

54-
async createEditors(container: HTMLElement): Promise<void> {
55-
if (this.config.useDiffEditor) {
56-
await this.createDiffEditor(container, this.config.diffEditorOptions);
57-
} else {
58-
await this.createEditor(container, this.config.editorOptions);
59-
}
60-
}
61-
6242
async init() {
6343
// await all extenson that should be ready beforehand
6444
await this.awaitReadiness(this.config.awaitExtensionReadiness);
@@ -109,15 +89,11 @@ export class EditorAppClassic extends EditorAppBase {
10989
different = isModelUpdateRequired(orgConfig, config) !== ModelUpdateType.none;
11090
}
11191
type ClassicKeys = keyof typeof orgConfig;
112-
const propsClassic = ['useDiffEditor', 'readOnly', 'domReadOnly', 'awaitExtensionReadiness', 'automaticLayout', 'languageDef', 'languageExtensionConfig', 'theme', 'themeData'];
113-
const propsClassicEditorOptions = ['editorOptions', 'diffEditorOptions'];
114-
92+
const propsClassic = ['useDiffEditor', 'domReadOnly', 'readOnly', 'awaitExtensionReadiness', 'overrideAutomaticLayout', 'editorOptions', 'diffEditorOptions', 'languageDef', 'languageExtensionConfig', 'theme', 'themeData'];
11593
const propCompareClassic = (name: string) => {
11694
return orgConfig[name as ClassicKeys] !== config[name as ClassicKeys];
11795
};
118-
11996
different = different || propsClassic.some(propCompareClassic);
120-
different = different || propsClassicEditorOptions.some(propCompareClassic);
12197
return different;
12298
}
12399
}

Diff for: packages/monaco-editor-wrapper/src/editorAppExtended.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,13 @@ export class EditorAppExtended extends EditorAppBase {
6565
return this.extensionRegisterResults.get(extensionName);
6666
}
6767

68-
override specifyService(): editor.IEditorOverrideServices {
68+
override specifyServices(): editor.IEditorOverrideServices {
6969
return {
7070
...getThemeServiceOverride(),
7171
...getTextmateServiceOverride()
7272
};
7373
}
7474

75-
async createEditors(container: HTMLElement): Promise<void> {
76-
if (this.config.useDiffEditor) {
77-
await this.createDiffEditor(container);
78-
} else {
79-
await this.createEditor(container);
80-
}
81-
}
82-
8375
override async init() {
8476
// await all extensions that should be ready beforehand
8577
// always await theme extension
@@ -118,7 +110,7 @@ export class EditorAppExtended extends EditorAppBase {
118110
if (includeModelData) {
119111
different = isModelUpdateRequired(orgConfig, config) !== ModelUpdateType.none;
120112
}
121-
const propsExtended = ['useDiffEditor', 'readOnly', 'domReadOnly', 'awaitExtensionReadiness', 'userConfiguration', 'extensions'];
113+
const propsExtended = ['useDiffEditor', 'domReadOnly', 'readOnly', 'awaitExtensionReadiness', 'overrideAutomaticLayout', 'editorOptions', 'diffEditorOptions', 'userConfiguration', 'extensions'];
122114
type ExtendedKeys = keyof typeof orgConfig;
123115
const propCompareExtended = (name: string) => {
124116
return orgConfig[name as ExtendedKeys] !== config[name as ExtendedKeys];

Diff for: packages/monaco-editor-wrapper/src/wrapper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class MonacoEditorLanguageClientWrapper {
5454
};
5555
mergeServices(mlcDefautServices, this.serviceConfig.userServices);
5656
}
57-
mergeServices(this.editorApp?.specifyService() ?? {}, this.serviceConfig.userServices);
57+
mergeServices(this.editorApp?.specifyServices() ?? {}, this.serviceConfig.userServices);
5858

5959
// overrule debug log flag
6060
this.serviceConfig.debugLogging = this.logger.isEnabled() && (this.serviceConfig.debugLogging || this.logger.isDebugEnabled());

Diff for: packages/monaco-editor-wrapper/test/wrapper.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Test MonacoEditorLanguageClientWrapper', () => {
2626
expect(app).toBeDefined();
2727

2828
const appConfig = app.getConfig();
29-
expect(appConfig.automaticLayout).toBeTruthy();
29+
expect(appConfig.overrideAutomaticLayout).toBeTruthy();
3030
expect(appConfig.theme).toBe('vs-light');
3131
});
3232

0 commit comments

Comments
 (0)