Skip to content

Commit

Permalink
First validate editor options, and then compute the result based on env
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed May 8, 2017
1 parent 4aa5aa4 commit b2091c5
Show file tree
Hide file tree
Showing 7 changed files with 625 additions and 305 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/browser/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class Configuration extends CommonEditorConfiguration {

this._register(CSSBasedConfiguration.INSTANCE.onDidChange(() => this._onCSSBasedConfigurationChanged()));

if (this._configWithDefaults.getEditorOptions().automaticLayout) {
if (this._validatedOptions.automaticLayout) {
this._elementSizeObserver.startObserving();
}

Expand Down
8 changes: 3 additions & 5 deletions src/vs/editor/browser/standalone/standaloneCodeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,18 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
if (typeof options.theme === 'string') {
options.theme = standaloneThemeService.setTheme(options.theme);
}

let model: IModel = options.model;
delete options.model;
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService);

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

let model: IModel = null;
if (typeof options.model === 'undefined') {
if (typeof model === 'undefined') {
model = (<any>self).monaco.editor.createModel(options.value || '', options.language || 'text/plain');
this._ownsModel = true;
} else {
model = options.model;
delete options.model;
this._ownsModel = false;
}

Expand Down
53 changes: 13 additions & 40 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,6 @@ export const TabFocus: ITabFocus = new class {
}
};

export class ConfigurationWithDefaults {

private _editor: editorOptions.IEditorOptions;

constructor(options: editorOptions.IEditorOptions) {
this._editor = <editorOptions.IEditorOptions>objects.clone(DefaultConfig.editor);

this._mergeOptionsIn(options);
}

public getEditorOptions(): editorOptions.IEditorOptions {
return this._editor;
}

private _mergeOptionsIn(newOptions: editorOptions.IEditorOptions): void {
this._editor = objects.mixin(this._editor, newOptions || {});
}

public updateOptions(newOptions: editorOptions.IEditorOptions): void {
// Apply new options
this._mergeOptionsIn(newOptions);
}
}

function toBoolean(value: any): boolean {
return value === 'false' ? false : Boolean(value);
}

export interface IElementSizeObserver {
startObserving(): void;
observe(dimension?: editorCommon.IDimension): void;
Expand All @@ -87,9 +59,11 @@ export interface IElementSizeObserver {

export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration {

protected _rawOptions: editorOptions.IEditorOptions;
protected _validatedOptions: editorOptions.IValidatedEditorOptions;

public editor: editorOptions.InternalEditorOptions;

protected _configWithDefaults: ConfigurationWithDefaults;
protected _elementSizeObserver: IElementSizeObserver;
private _isDominatedByLongLines: boolean;
private _lineNumbersDigitCount: number;
Expand All @@ -99,7 +73,10 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed

constructor(options: editorOptions.IEditorOptions, elementSizeObserver: IElementSizeObserver = null) {
super();
this._configWithDefaults = new ConfigurationWithDefaults(options);

this._rawOptions = options;
this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, editorOptions.DEFAULTS);

this._elementSizeObserver = elementSizeObserver;
this._isDominatedByLongLines = false;
this._lineNumbersDigitCount = 1;
Expand Down Expand Up @@ -127,33 +104,29 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
}

public getRawOptions(): editorOptions.IEditorOptions {
return this._configWithDefaults.getEditorOptions();
return this._rawOptions;
}

private _computeInternalOptions(): editorOptions.InternalEditorOptions {
let opts = this._configWithDefaults.getEditorOptions();

let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures), opts.mouseStyle);

let bareFontInfo = BareFontInfo.createFromRawSettings(opts, this.getZoomLevel());

const opts = this._validatedOptions;
const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, this.getZoomLevel());
const env = new editorOptions.EnvironmentalOptions({
outerWidth: this.getOuterWidth(),
outerHeight: this.getOuterHeight(),
fontInfo: this.readConfiguration(bareFontInfo),
editorClassName: editorClassName,
editorClassName: this._getEditorClassName(opts.theme, opts.fontLigatures, opts.mouseStyle),
isDominatedByLongLines: this._isDominatedByLongLines,
lineNumbersDigitCount: this._lineNumbersDigitCount,
canUseTranslate3d: this._getCanUseTranslate3d(),
pixelRatio: this._getPixelRatio(),
tabFocusMode: TabFocus.getTabFocusMode()
});

return editorOptions.InternalEditorOptionsFactory.createInternalEditorOptions(env, opts);
}

public updateOptions(newOptions: editorOptions.IEditorOptions): void {
this._configWithDefaults.updateOptions(newOptions);
this._rawOptions = objects.mixin(this._rawOptions, newOptions || {});
this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, editorOptions.DEFAULTS);
this._recomputeOptions();
}

Expand Down
Loading

0 comments on commit b2091c5

Please sign in to comment.