Skip to content
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
43 changes: 19 additions & 24 deletions src/vs/editor/browser/standalone/standaloneCodeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,26 @@ export interface IEditorConstructionOptions extends IEditorOptions {
* To not create automatically a model, use `model: null`.
*/
language?: string;
/**
* Initial 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;
}

/**
* The options to create a diff editor.
*/
export interface IDiffEditorConstructionOptions extends IDiffEditorOptions {
/**
* Initial 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;
}

export interface IStandaloneCodeEditor extends ICodeEditor {
Expand Down Expand Up @@ -193,7 +207,6 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor {

private _contextViewService: IEditorContextViewService;
private _standaloneThemeService: IStandaloneThemeService;
private _ownsModel: boolean;

constructor(
Expand All @@ -206,18 +219,17 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
@IContextKeyService contextKeyService: IContextKeyService,
@IKeybindingService keybindingService: IKeybindingService,
@IContextViewService contextViewService: IContextViewService,
@IStandaloneThemeService standaloneThemeService: IStandaloneThemeService
@IStandaloneThemeService themeService: IStandaloneThemeService
) {
options = options || {};
if (typeof options.theme === 'string') {
options.theme = standaloneThemeService.setTheme(options.theme);
themeService.setTheme(options.theme);
}
let model: IModel = options.model;
delete options.model;
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, standaloneThemeService);
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService);

this._contextViewService = <IEditorContextViewService>contextViewService;
this._standaloneThemeService = standaloneThemeService;
this._register(toDispose);

if (typeof model === 'undefined') {
Expand Down Expand Up @@ -245,13 +257,6 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
this.dispose();
}

public updateOptions(newOptions: IEditorOptions): void {
if (typeof newOptions.theme === 'string') {
newOptions.theme = this._standaloneThemeService.setTheme(newOptions.theme);
}
super.updateOptions(newOptions);
}

_attachModel(model: IModel): void {
super._attachModel(model);
if (this._view) {
Expand All @@ -271,7 +276,6 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor {

private _contextViewService: IEditorContextViewService;
private _standaloneThemeService: IStandaloneThemeService;
private _standaloneKeybindingService: StandaloneKeybindingService;

constructor(
Expand All @@ -282,14 +286,13 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
@IContextKeyService contextKeyService: IContextKeyService,
@IKeybindingService keybindingService: IKeybindingService,
@IContextViewService contextViewService: IContextViewService,
@IStandaloneThemeService standaloneColorService: IStandaloneThemeService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@IThemeService themeService: IThemeService
@IStandaloneThemeService themeService: IStandaloneThemeService
) {
options = options || {};
if (typeof options.theme === 'string') {
options.theme = standaloneColorService.setTheme(options.theme);
options.theme = themeService.setTheme(options.theme);
}

super(domElement, options, editorWorkerService, contextKeyService, instantiationService, codeEditorService, themeService);
Expand All @@ -299,7 +302,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
}

this._contextViewService = <IEditorContextViewService>contextViewService;
this._standaloneThemeService = standaloneColorService;

this._register(toDispose);

Expand All @@ -314,13 +316,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
this.dispose();
}

public updateOptions(newOptions: IEditorOptions): void {
if (typeof newOptions.theme === 'string') {
newOptions.theme = this._standaloneThemeService.setTheme(newOptions.theme);
}
super.updateOptions(newOptions);
}

protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditor {
return instantiationService.createInstance(StandaloneCodeEditor, container, options);
}
Expand Down
9 changes: 8 additions & 1 deletion src/vs/editor/browser/standalone/standaloneEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorC
services.get(IContextKeyService),
services.get(IKeybindingService),
services.get(IContextViewService),
services.get(IStandaloneThemeService),
services.get(IEditorWorkerService),
services.get(ICodeEditorService),
services.get(IStandaloneThemeService)
Expand Down Expand Up @@ -309,6 +308,13 @@ export function defineTheme(themeName: string, themeData: IStandaloneThemeData):
StaticServices.standaloneThemeService.get().defineTheme(themeName, themeData);
}

/**
* Switches to a theme.
*/
export function setTheme(themeName: string): void {
StaticServices.standaloneThemeService.get().setTheme(themeName);
}

/**
* @internal
*/
Expand Down Expand Up @@ -336,6 +342,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
colorizeModelLine: colorizeModelLine,
tokenize: tokenize,
defineTheme: defineTheme,
setTheme: setTheme,

// enums
ScrollbarVisibility: ScrollbarVisibility,
Expand Down
15 changes: 12 additions & 3 deletions src/vs/editor/browser/view/viewImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'
import { EditorScrollbar } from 'vs/editor/browser/viewParts/editorScrollbar/editorScrollbar';
import { Minimap } from 'vs/editor/browser/viewParts/minimap/minimap';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IThemeService, getThemeTypeSelector } from 'vs/platform/theme/common/themeService';

export interface IContentWidgetData {
widget: editorBrowser.IContentWidget;
Expand Down Expand Up @@ -118,6 +118,7 @@ export class View extends ViewEventHandler {
this._register(themeService.onThemeChange(theme => {
this._context.theme = theme;
this.eventDispatcher.emit(new viewEvents.ViewThemeChangedEvent());
this.render(true, false);
}));

this.viewParts = [];
Expand All @@ -144,7 +145,7 @@ export class View extends ViewEventHandler {
this.linesContent.setPosition('absolute');

this.domNode = createFastDomNode(document.createElement('div'));
this.domNode.setClassName(this._context.configuration.editor.editorClassName);
this.domNode.setClassName(this.getEditorClassName());

this.overflowGuardContainer = createFastDomNode(document.createElement('div'));
PartFingerprints.write(this.overflowGuardContainer, PartFingerprint.OverflowGuard);
Expand Down Expand Up @@ -305,11 +306,15 @@ export class View extends ViewEventHandler {

}

private getEditorClassName() {
return this._context.configuration.editor.editorClassName + ' ' + getThemeTypeSelector(this._context.theme.type);
}

// --- begin event handlers

public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {
if (e.editorClassName) {
this.domNode.setClassName(this._context.configuration.editor.editorClassName);
this.domNode.setClassName(this.getEditorClassName());
}
if (e.layoutInfo) {
this._setLayout();
Expand All @@ -329,6 +334,10 @@ export class View extends ViewEventHandler {
this.outgoingEvents.emitScrollChanged(e);
return false;
}
public onThemeChanged(e: viewEvents.ViewThemeChangedEvent): boolean {
this.domNode.setClassName(this.getEditorClassName());
return false;
}

// --- end event handlers

Expand Down
10 changes: 0 additions & 10 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
super.dispose();
}

public updateOptions(newOptions: IEditorOptions): void {
let oldTheme = this._configuration.editor.viewInfo.theme;
super.updateOptions(newOptions);
let newTheme = this._configuration.editor.viewInfo.theme;

if (oldTheme !== newTheme) {
this.render();
}
}

public colorizeModelLine(lineNumber: number, model: editorCommon.IModel = this.model): string {
if (!model) {
return '';
Expand Down
26 changes: 11 additions & 15 deletions src/vs/editor/browser/widget/diffEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import { ColorId, MetadataConsts, FontStyle } from 'vs/editor/common/modes';
import Event, { Emitter } from 'vs/base/common/event';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { registerThemingParticipant, IThemeService, ITheme } from 'vs/platform/theme/common/themeService';
import { registerThemingParticipant, IThemeService, ITheme, getThemeTypeSelector } from 'vs/platform/theme/common/themeService';
import { registerColor, scrollbarShadow } from 'vs/platform/theme/common/colorRegistry';
import { Color, RGBA } from 'vs/base/common/color';
import { OverviewRulerZone } from 'vs/editor/common/view/overviewZoneManager';
Expand Down Expand Up @@ -148,7 +148,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE

private readonly id: number;

private _theme: string;
private _domElement: HTMLElement;
protected readonly _containerDomElement: HTMLElement;
private readonly _overviewDomElement: HTMLElement;
Expand Down Expand Up @@ -213,7 +212,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._domElement = domElement;
options = options || {};

this._theme = options.theme || editorOptions.EDITOR_DEFAULTS.viewInfo.theme;
// renderSideBySide
this._renderSideBySide = true;
if (typeof options.renderSideBySide !== 'undefined') {
Expand All @@ -240,7 +238,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._updateDecorationsRunner = this._register(new RunOnceScheduler(() => this._updateDecorations(), 0));

this._containerDomElement = document.createElement('div');
this._containerDomElement.className = DiffEditorWidget._getClassName(this._theme, this._renderSideBySide);
this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
this._containerDomElement.style.position = 'relative';
this._containerDomElement.style.height = '100%';
this._domElement.appendChild(this._containerDomElement);
Expand Down Expand Up @@ -305,11 +303,12 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE

this._codeEditorService.addDiffEditor(this);

themeService.onThemeChange(t => {
this._register(themeService.onThemeChange(t => {
if (this._strategy && this._strategy.applyColors(t)) {
this._updateDecorationsRunner.schedule();
}
});
this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
}));
}

public get ignoreTrimWhitespace(): boolean {
Expand All @@ -324,12 +323,12 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return this._renderIndicators;
}

private static _getClassName(theme: string, renderSideBySide: boolean): string {
private static _getClassName(theme: ITheme, renderSideBySide: boolean): string {
let result = 'monaco-diff-editor monaco-editor-background ';
if (renderSideBySide) {
result += 'side-by-side ';
}
result += theme;
result += getThemeTypeSelector(theme.type);
return result;
}

Expand Down Expand Up @@ -486,8 +485,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
}

public updateOptions(newOptions: editorOptions.IDiffEditorOptions): void {
// Handle new theme
this._theme = newOptions && newOptions.theme ? newOptions.theme : this._theme;

// Handle side by side
let renderSideBySideChanged = false;
Expand Down Expand Up @@ -523,9 +520,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._originalIsEditable = Boolean(newOptions.originalEditable);
}

// Update class name
this._containerDomElement.className = DiffEditorWidget._getClassName(this._theme, this._renderSideBySide);

this.modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(newOptions));
this.originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(newOptions, this._originalIsEditable));

Expand All @@ -542,6 +536,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
} else {
this._setStrategy(new DiffEdtorWidgetInline(this._createDataSource(), this._enableSplitViewResizing));
}
// Update class name
this._containerDomElement.className = DiffEditorWidget._getClassName(this._themeService.getTheme(), this._renderSideBySide);
}
}

Expand Down Expand Up @@ -892,15 +888,15 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
let result = this._adjustOptionsForSubEditor(options);
result.readOnly = !isEditable;
result.overviewRulerLanes = 1;
result.theme = this._theme + ' original-in-monaco-diff-editor';
result.extraEditorClassName = 'original-in-monaco-diff-editor';
return result;
}

private _adjustOptionsForRightHandSide(options: editorOptions.IDiffEditorOptions): editorOptions.IEditorOptions {
let result = this._adjustOptionsForSubEditor(options);
result.revealHorizontalRightPadding = editorOptions.EDITOR_DEFAULTS.viewInfo.revealHorizontalRightPadding + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH;
result.scrollbar.verticalHasArrows = false;
result.theme = this._theme + ' modified-in-monaco-diff-editor';
result.extraEditorClassName = 'modified-in-monaco-diff-editor';
return result;
}

Expand Down
17 changes: 1 addition & 16 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
const opts = this._validatedOptions;
const partialEnv = this._getEnvConfiguration();
const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, partialEnv.zoomLevel);
const editorClassName = this._getEditorClassName(opts.viewInfo.theme, opts.viewInfo.fontLigatures, opts.mouseStyle);
const env: editorOptions.IEnvironmentalOptions = {
outerWidth: partialEnv.outerWidth,
outerHeight: partialEnv.outerHeight,
fontInfo: this.readConfiguration(bareFontInfo),
editorClassName: editorClassName + ' ' + partialEnv.extraEditorClassName,
extraEditorClassName: partialEnv.extraEditorClassName,
isDominatedByLongLines: this._isDominatedByLongLines,
lineNumbersDigitCount: this._lineNumbersDigitCount,
canUseTranslate3d: partialEnv.canUseTranslate3d,
Expand Down Expand Up @@ -154,20 +153,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
}
return r ? r : 1;
}

private _getEditorClassName(theme: string, fontLigatures: boolean, mouseStyle: 'text' | 'default' | 'copy'): string {
let extra = '';
if (fontLigatures) {
extra += 'enable-ligatures ';
}
if (mouseStyle === 'default') {
extra += 'mouse-default ';
} else if (mouseStyle === 'copy') {
extra += 'mouse-copy ';
}
return 'monaco-editor ' + extra + theme;
}

protected abstract _getEnvConfiguration(): IEnvConfiguration;

protected abstract readConfiguration(styling: BareFontInfo): FontInfo;
Expand Down
Loading