From 37f2127173cf8d3185ec0ea27a7643fdcddbb07b Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 17 Feb 2020 21:01:26 +0100 Subject: [PATCH] Fixes microsoft/monaco-editor#1832: Accept `theme` to be passed in to `updateOptions` --- .../browser/standaloneCodeEditor.ts | 19 ++++++++++++++++++- src/vs/monaco.d.ts | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts index 7f1e39821e73..504f3d2356fe 100644 --- a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts @@ -124,6 +124,13 @@ export interface IGlobalEditorOptions { * Defaults to 20000. */ maxTokenizationLineLength?: number; + /** + * Theme to be used for rendering. + * The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black'. + * You can create custom themes via `monaco.editor.defineTheme`. + * To switch a theme, use `monaco.editor.setTheme` + */ + theme?: string; } /** @@ -334,6 +341,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon private readonly _contextViewService: ContextViewService; private readonly _configurationService: IConfigurationService; + private readonly _standaloneThemeService: IStandaloneThemeService; private _ownsModel: boolean; constructor( @@ -363,6 +371,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon this._contextViewService = contextViewService; this._configurationService = configurationService; + this._standaloneThemeService = themeService; this._register(toDispose); this._register(themeDomRegistration); @@ -391,6 +400,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon public updateOptions(newOptions: IEditorOptions & IGlobalEditorOptions): void { applyConfigurationValues(this._configurationService, newOptions, false); + if (typeof newOptions.theme === 'string') { + this._standaloneThemeService.setTheme(newOptions.theme); + } super.updateOptions(newOptions); } @@ -414,6 +426,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon private readonly _contextViewService: ContextViewService; private readonly _configurationService: IConfigurationService; + private readonly _standaloneThemeService: IStandaloneThemeService; constructor( domElement: HTMLElement, @@ -443,6 +456,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon this._contextViewService = contextViewService; this._configurationService = configurationService; + this._standaloneThemeService = themeService; this._register(toDispose); this._register(themeDomRegistration); @@ -454,8 +468,11 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon super.dispose(); } - public updateOptions(newOptions: IDiffEditorOptions): void { + public updateOptions(newOptions: IDiffEditorOptions & IGlobalEditorOptions): void { applyConfigurationValues(this._configurationService, newOptions, true); + if (typeof newOptions.theme === 'string') { + this._standaloneThemeService.setTheme(newOptions.theme); + } super.updateOptions(newOptions); } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 73a615757dc4..ccd369acc0dd 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -1108,6 +1108,13 @@ declare namespace monaco.editor { * Defaults to 20000. */ maxTokenizationLineLength?: number; + /** + * Theme to be used for rendering. + * The current out-of-the-box available themes are: 'vs' (default), 'vs-dark', 'hc-black'. + * You can create custom themes via `monaco.editor.defineTheme`. + * To switch a theme, use `monaco.editor.setTheme` + */ + theme?: string; } /**