diff --git a/src/vs/editor/browser/config/configuration.ts b/src/vs/editor/browser/config/configuration.ts index 330903d01af45870c03eaf48e24dfa0ac314a667..80191982f21f72a8099352f25aa8bcac5c6c634f 100644 --- a/src/vs/editor/browser/config/configuration.ts +++ b/src/vs/editor/browser/config/configuration.ts @@ -8,7 +8,7 @@ import Event, { Emitter } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as platform from 'vs/base/common/platform'; import * as browser from 'vs/base/browser/browser'; -import { CommonEditorConfiguration } from 'vs/editor/common/config/commonEditorConfig'; +import { CommonEditorConfiguration, IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; import { IDimension } from 'vs/editor/common/editorCommon'; import { FontInfo, BareFontInfo } from 'vs/editor/common/config/fontInfo'; import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver'; @@ -309,8 +309,12 @@ export class Configuration extends CommonEditorConfiguration { domNode.setLineHeight(fontInfo.lineHeight); } + private readonly _elementSizeObserver: ElementSizeObserver; + constructor(options: IEditorOptions, referenceDomElement: HTMLElement = null) { - super(options, new ElementSizeObserver(referenceDomElement, () => this._onReferenceDomElementSizeChanged())); + super(options); + + this._elementSizeObserver = this._register(new ElementSizeObserver(referenceDomElement, () => this._onReferenceDomElementSizeChanged())); this._register(CSSBasedConfiguration.INSTANCE.onDidChange(() => this._onCSSBasedConfigurationChanged())); @@ -319,6 +323,8 @@ export class Configuration extends CommonEditorConfiguration { } this._register(browser.onDidChangeZoomLevel(_ => this._recomputeOptions())); + + this._recomputeOptions(); } private _onReferenceDomElementSizeChanged(): void { @@ -334,11 +340,10 @@ export class Configuration extends CommonEditorConfiguration { } public dispose(): void { - this._elementSizeObserver.dispose(); super.dispose(); } - protected _getEditorClassName(theme: string, fontLigatures: boolean, mouseStyle: 'text' | 'default' | 'copy'): string { + private _getExtraEditorClassName(): string { let extra = ''; if (browser.isIE) { extra += 'ie '; @@ -350,38 +355,21 @@ export class Configuration extends CommonEditorConfiguration { if (platform.isMacintosh) { extra += 'mac '; } - if (fontLigatures) { - extra += 'enable-ligatures '; - } - if (mouseStyle === 'default') { - extra += 'mouse-default '; - } else if (mouseStyle === 'copy') { - extra += 'mouse-copy '; - } - return 'monaco-editor ' + extra + theme; - } - - protected getOuterWidth(): number { - return this._elementSizeObserver.getWidth(); - } - - protected getOuterHeight(): number { - return this._elementSizeObserver.getHeight(); + return extra; } - protected _getCanUseTranslate3d(): boolean { - return browser.canUseTranslate3d(); - } - - protected _getPixelRatio(): number { - return browser.getPixelRatio(); + protected _getEnvConfiguration(): IEnvConfiguration { + return { + extraEditorClassName: this._getExtraEditorClassName(), + outerWidth: this._elementSizeObserver.getWidth(), + outerHeight: this._elementSizeObserver.getHeight(), + canUseTranslate3d: browser.canUseTranslate3d(), + pixelRatio: browser.getPixelRatio(), + zoomLevel: browser.getZoomLevel() + }; } protected readConfiguration(bareFontInfo: BareFontInfo): FontInfo { return CSSBasedConfiguration.INSTANCE.readConfiguration(bareFontInfo); } - - protected getZoomLevel(): number { - return browser.getZoomLevel(); - } } diff --git a/src/vs/editor/browser/config/elementSizeObserver.ts b/src/vs/editor/browser/config/elementSizeObserver.ts index ee21f6c21bda665c34d5ea5900296affcb1be6d8..bd8814cace914eadebb3bfa7b40e41d0b6a215f1 100644 --- a/src/vs/editor/browser/config/elementSizeObserver.ts +++ b/src/vs/editor/browser/config/elementSizeObserver.ts @@ -6,9 +6,8 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { IDimension } from 'vs/editor/common/editorCommon'; -import { IElementSizeObserver } from 'vs/editor/common/config/commonEditorConfig'; -export class ElementSizeObserver extends Disposable implements IElementSizeObserver { +export class ElementSizeObserver extends Disposable { private referenceDomElement: HTMLElement; private measureReferenceDomElementToken: number; diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 62ca9dfe17313f6f739e6f492c7d95c27dc42680..172b427f1b3e2f9b341e4dae534bc6049784213c 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -51,38 +51,35 @@ export const TabFocus: ITabFocus = new class { } }; -export interface IElementSizeObserver { - startObserving(): void; - observe(dimension?: editorCommon.IDimension): void; - dispose(): void; - getWidth(): number; - getHeight(): number; +export interface IEnvConfiguration { + extraEditorClassName: string; + outerWidth: number; + outerHeight: number; + canUseTranslate3d: boolean; + pixelRatio: number; + zoomLevel: number; } export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { protected _rawOptions: editorOptions.IEditorOptions; protected _validatedOptions: editorOptions.IValidatedEditorOptions; - public editor: editorOptions.InternalEditorOptions; - - protected _elementSizeObserver: IElementSizeObserver; private _isDominatedByLongLines: boolean; private _lineNumbersDigitCount: number; private _onDidChange = this._register(new Emitter()); public onDidChange: Event = this._onDidChange.event; - constructor(options: editorOptions.IEditorOptions, elementSizeObserver: IElementSizeObserver = null) { + constructor(options: editorOptions.IEditorOptions) { super(); this._rawOptions = options || {}; this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); - - this._elementSizeObserver = elementSizeObserver; + this.editor = null; this._isDominatedByLongLines = false; this._lineNumbersDigitCount = 1; - this.editor = this._computeInternalOptions(); + this._register(EditorZoom.onDidChangeZoomLevel(_ => this._recomputeOptions())); this._register(TabFocus.onDidChangeTabFocus(_ => this._recomputeOptions())); } @@ -92,17 +89,18 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed } protected _recomputeOptions(): void { - this._setOptions(this._computeInternalOptions()); - } + const oldOptions = this.editor; + const newOptions = this._computeInternalOptions(); - private _setOptions(newOptions: editorOptions.InternalEditorOptions): void { - if (this.editor && this.editor.equals(newOptions)) { + if (oldOptions && oldOptions.equals(newOptions)) { return; } - let changeEvent = this.editor.createChangeEvent(newOptions); this.editor = newOptions; - this._onDidChange.fire(changeEvent); + + if (oldOptions) { + this._onDidChange.fire(oldOptions.createChangeEvent(newOptions)); + } } public getRawOptions(): editorOptions.IEditorOptions { @@ -111,16 +109,18 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed private _computeInternalOptions(): editorOptions.InternalEditorOptions { const opts = this._validatedOptions; - const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, this.getZoomLevel()); + 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: this.getOuterWidth(), - outerHeight: this.getOuterHeight(), + outerWidth: partialEnv.outerWidth, + outerHeight: partialEnv.outerHeight, fontInfo: this.readConfiguration(bareFontInfo), - editorClassName: this._getEditorClassName(opts.viewInfo.theme, opts.viewInfo.fontLigatures, opts.mouseStyle), + editorClassName: editorClassName + ' ' + partialEnv.extraEditorClassName, isDominatedByLongLines: this._isDominatedByLongLines, lineNumbersDigitCount: this._lineNumbersDigitCount, - canUseTranslate3d: this._getCanUseTranslate3d(), - pixelRatio: this._getPixelRatio(), + canUseTranslate3d: partialEnv.canUseTranslate3d, + pixelRatio: partialEnv.pixelRatio, tabFocusMode: TabFocus.getTabFocusMode() }; return editorOptions.InternalEditorOptionsFactory.createInternalEditorOptions(env, opts); @@ -155,19 +155,23 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed return r ? r : 1; } - protected abstract _getEditorClassName(theme: string, fontLigatures: boolean, mouseDrag: 'text' | 'default' | 'copy'): string; - - protected abstract getOuterWidth(): number; - - protected abstract getOuterHeight(): number; - - protected abstract _getCanUseTranslate3d(): boolean; + 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 _getPixelRatio(): number; + protected abstract _getEnvConfiguration(): IEnvConfiguration; protected abstract readConfiguration(styling: BareFontInfo): FontInfo; - protected abstract getZoomLevel(): number; } const configurationRegistry = Registry.as(Extensions.Configuration); diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index bda2f542ccb6b46841ecd5133ba0381b577e22e7..e98f7cc203c9a2c7a8b3c2cb2e1f3ed7b90a902e 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -7,6 +7,7 @@ import * as assert from 'assert'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; +import { IEnvConfiguration } from "vs/editor/common/config/commonEditorConfig"; suite('Common Editor Config', () => { test('Zoom Level', () => { @@ -52,8 +53,15 @@ suite('Common Editor Config', () => { }); class TestWrappingConfiguration extends TestConfiguration { - protected getOuterWidth(): number { - return 1000; + protected _getEnvConfiguration(): IEnvConfiguration { + return { + extraEditorClassName: '', + outerWidth: 1000, + outerHeight: 100, + canUseTranslate3d: true, + pixelRatio: 1, + zoomLevel: 0 + }; } } diff --git a/src/vs/editor/test/common/mocks/testConfiguration.ts b/src/vs/editor/test/common/mocks/testConfiguration.ts index d8cede0b45b09f2d76df77ea7785d8e5d3da6dec..41917c57f23a89c1a43809771640c7105f924735 100644 --- a/src/vs/editor/test/common/mocks/testConfiguration.ts +++ b/src/vs/editor/test/common/mocks/testConfiguration.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { CommonEditorConfiguration } from 'vs/editor/common/config/commonEditorConfig'; +import { CommonEditorConfiguration, IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { FontInfo, BareFontInfo } from 'vs/editor/common/config/fontInfo'; @@ -12,26 +12,18 @@ export class TestConfiguration extends CommonEditorConfiguration { constructor(opts: IEditorOptions) { super(opts); + this._recomputeOptions(); } - protected _getEditorClassName(theme: string, fontLigatures: boolean): string { - return ''; - } - - protected getOuterWidth(): number { - return 100; - } - - protected getOuterHeight(): number { - return 100; - } - - protected _getCanUseTranslate3d(): boolean { - return true; - } - - protected _getPixelRatio(): number { - return 1; + protected _getEnvConfiguration(): IEnvConfiguration { + return { + extraEditorClassName: '', + outerWidth: 100, + outerHeight: 100, + canUseTranslate3d: true, + pixelRatio: 1, + zoomLevel: 0 + }; } protected readConfiguration(styling: BareFontInfo): FontInfo { @@ -48,8 +40,4 @@ export class TestConfiguration extends CommonEditorConfiguration { maxDigitWidth: 10, }, true); } - - protected getZoomLevel(): number { - return 0; - } }