Skip to content

Commit 37f2127

Browse files
committed
Fixes microsoft/monaco-editor#1832: Accept theme to be passed in to updateOptions
1 parent b308a36 commit 37f2127

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/vs/editor/standalone/browser/standaloneCodeEditor.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export interface IGlobalEditorOptions {
124124
* Defaults to 20000.
125125
*/
126126
maxTokenizationLineLength?: number;
127+
/**
128+
* Theme to be used for rendering.
129+
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black'.
130+
* You can create custom themes via `monaco.editor.defineTheme`.
131+
* To switch a theme, use `monaco.editor.setTheme`
132+
*/
133+
theme?: string;
127134
}
128135

129136
/**
@@ -334,6 +341,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
334341

335342
private readonly _contextViewService: ContextViewService;
336343
private readonly _configurationService: IConfigurationService;
344+
private readonly _standaloneThemeService: IStandaloneThemeService;
337345
private _ownsModel: boolean;
338346

339347
constructor(
@@ -363,6 +371,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
363371

364372
this._contextViewService = <ContextViewService>contextViewService;
365373
this._configurationService = configurationService;
374+
this._standaloneThemeService = themeService;
366375
this._register(toDispose);
367376
this._register(themeDomRegistration);
368377

@@ -391,6 +400,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
391400

392401
public updateOptions(newOptions: IEditorOptions & IGlobalEditorOptions): void {
393402
applyConfigurationValues(this._configurationService, newOptions, false);
403+
if (typeof newOptions.theme === 'string') {
404+
this._standaloneThemeService.setTheme(newOptions.theme);
405+
}
394406
super.updateOptions(newOptions);
395407
}
396408

@@ -414,6 +426,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
414426

415427
private readonly _contextViewService: ContextViewService;
416428
private readonly _configurationService: IConfigurationService;
429+
private readonly _standaloneThemeService: IStandaloneThemeService;
417430

418431
constructor(
419432
domElement: HTMLElement,
@@ -443,6 +456,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
443456

444457
this._contextViewService = <ContextViewService>contextViewService;
445458
this._configurationService = configurationService;
459+
this._standaloneThemeService = themeService;
446460

447461
this._register(toDispose);
448462
this._register(themeDomRegistration);
@@ -454,8 +468,11 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
454468
super.dispose();
455469
}
456470

457-
public updateOptions(newOptions: IDiffEditorOptions): void {
471+
public updateOptions(newOptions: IDiffEditorOptions & IGlobalEditorOptions): void {
458472
applyConfigurationValues(this._configurationService, newOptions, true);
473+
if (typeof newOptions.theme === 'string') {
474+
this._standaloneThemeService.setTheme(newOptions.theme);
475+
}
459476
super.updateOptions(newOptions);
460477
}
461478

src/vs/monaco.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,13 @@ declare namespace monaco.editor {
11081108
* Defaults to 20000.
11091109
*/
11101110
maxTokenizationLineLength?: number;
1111+
/**
1112+
* Theme to be used for rendering.
1113+
* The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black'.
1114+
* You can create custom themes via `monaco.editor.defineTheme`.
1115+
* To switch a theme, use `monaco.editor.setTheme`
1116+
*/
1117+
theme?: string;
11111118
}
11121119

11131120
/**

0 commit comments

Comments
 (0)