store pending config change event and 'replay' when becoming visible, fixes #9892

This commit is contained in:
Johannes Rieken 2016-07-28 16:12:24 +02:00
parent 89fbf8c8e4
commit e466584a67
5 changed files with 50 additions and 54 deletions

View file

@ -541,44 +541,33 @@ export class EditorConfiguration {
/**
* Ask the provided configuration service to apply its configuration to the provided editor.
*/
public static apply(config:any, editor?:editorCommon.IEditor): void;
public static apply(config:any, editor?:editorCommon.IEditor[]): void;
public static apply(config:any, editorOrArray?:any): void {
public static apply(config: any, editor: editorCommon.IEditor): void {
if (!config) {
return;
}
let editors:editorCommon.IEditor[] = editorOrArray;
if (!Array.isArray(editorOrArray)) {
editors = [editorOrArray];
}
// Editor Settings (Code Editor, Diff, Terminal)
if (editor && typeof editor.updateOptions === 'function') {
let type = editor.getEditorType();
if (type !== editorCommon.EditorType.ICodeEditor && type !== editorCommon.EditorType.IDiffEditor) {
return;
}
for (let i = 0; i < editors.length; i++) {
let editor = editors[i];
// Editor Settings (Code Editor, Diff, Terminal)
if (editor && typeof editor.updateOptions === 'function') {
let type = editor.getEditorType();
if (type !== editorCommon.EditorType.ICodeEditor && type !== editorCommon.EditorType.IDiffEditor) {
continue;
}
let editorConfig = config[EditorConfiguration.EDITOR_SECTION];
if (type === editorCommon.EditorType.IDiffEditor) {
let diffEditorConfig = config[EditorConfiguration.DIFF_EDITOR_SECTION];
if (diffEditorConfig) {
if (!editorConfig) {
editorConfig = diffEditorConfig;
} else {
editorConfig = objects.mixin(editorConfig, diffEditorConfig);
}
let editorConfig = config[EditorConfiguration.EDITOR_SECTION];
if (type === editorCommon.EditorType.IDiffEditor) {
let diffEditorConfig = config[EditorConfiguration.DIFF_EDITOR_SECTION];
if (diffEditorConfig) {
if (!editorConfig) {
editorConfig = diffEditorConfig;
} else {
editorConfig = objects.mixin(editorConfig, diffEditorConfig);
}
}
}
if (editorConfig) {
delete editorConfig.readOnly; // Prevent someone from making editor readonly
editor.updateOptions(editorConfig);
}
if (editorConfig) {
delete editorConfig.readOnly; // Prevent someone from making editor readonly
editor.updateOptions(editorConfig);
}
}
}

View file

@ -47,7 +47,6 @@ export interface IModeService {
configureMode(modeName: string, options: any): void;
configureModeById(modeId: string, options: any): void;
configureAllModes(config:any): void;
getConfigurationForMode(modeId:string): any;
// --- reading

View file

@ -192,7 +192,7 @@ export class ModeServiceImpl implements IModeService {
}
}
public configureAllModes(config:any): void {
protected _configureAllModes(config:any): void {
if (!config) {
return;
}
@ -588,6 +588,9 @@ export class MainThreadModeServiceImpl extends ModeServiceImpl {
private onConfigurationChange(configuration: IFilesConfiguration): void {
// Update Languages
this._configureAllModes(configuration);
// Clear user configured mime associations
mime.clearTextMimes(true /* user configured */);

View file

@ -22,9 +22,6 @@ export class MockModeService implements IModeService {
configureModeById(modeId: string, options: any): void {
throw new Error('Not implemented');
}
configureAllModes(config:any): void {
throw new Error('Not implemented');
}
getConfigurationForMode(modeId:string): any {
throw new Error('Not implemented');
}

View file

@ -9,7 +9,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {Dimension, Builder} from 'vs/base/browser/builder';
import objects = require('vs/base/common/objects');
import {CodeEditorWidget} from 'vs/editor/browser/widget/codeEditorWidget';
import {OptionsChangeEvent, EventType as WorkbenchEventType} from 'vs/workbench/common/events';
import {EventType as WorkbenchEventType} from 'vs/workbench/common/events';
import {EditorInput, EditorOptions} from 'vs/workbench/common/editor';
import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {EditorConfiguration} from 'vs/editor/common/config/commonEditorConfig';
@ -35,6 +35,7 @@ import {Selection} from 'vs/editor/common/core/selection';
export abstract class BaseTextEditor extends BaseEditor {
private editorControl: IEditor;
private _editorContainer: Builder;
private _hasPendingConfigurationChange = false;
constructor(
id: string,
@ -51,10 +52,10 @@ export abstract class BaseTextEditor extends BaseEditor {
) {
super(id, telemetryService);
this.toUnbind.push(this._eventService.addListener2(WorkbenchEventType.WORKBENCH_OPTIONS_CHANGED, (e) => this.onOptionsChanged(e)));
this.toUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.applyConfiguration(e.config)));
this.toUnbind.push(this._eventService.addListener2(WorkbenchEventType.WORKBENCH_OPTIONS_CHANGED, _ => this.handleConfigurationChangeEvent()));
this.toUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.handleConfigurationChangeEvent(e.config)));
this.toUnbind.push(_themeService.onDidThemeChange(_ => this.onThemeChanged()));
this.toUnbind.push(_themeService.onDidThemeChange(_ => this.handleConfigurationChangeEvent()));
}
public get instantiationService(): IInstantiationService {
@ -73,31 +74,37 @@ export abstract class BaseTextEditor extends BaseEditor {
return this._messageService;
}
protected applyConfiguration(configuration: IFilesConfiguration): void {
private handleConfigurationChangeEvent(configuration?: any): void {
if (this.isVisible()) {
this.applyConfiguration(configuration);
} else {
this._hasPendingConfigurationChange = true;
}
}
// Update Editor with configuration and editor settings
if (this.editorControl) {
private consumePendingConfigurationChangeEvent(): void {
if (this._hasPendingConfigurationChange) {
this.applyConfiguration(this.configurationService.getConfiguration());
this._hasPendingConfigurationChange = false;
}
}
protected applyConfiguration(configuration?: any): void {
if (!this.editorControl) {
return;
}
if (configuration) {
// Update Editor with configuration and editor settings
let specificEditorSettings = this.getCodeEditorOptions();
configuration = objects.clone(configuration); // dont modify original config
objects.assign(configuration[EditorConfiguration.EDITOR_SECTION], specificEditorSettings);
EditorConfiguration.apply(configuration, this.editorControl);
}
// Update Languages
this._modeService.configureAllModes(configuration);
}
private onOptionsChanged(event: OptionsChangeEvent): void {
if (this.editorControl) {
} else {
this.editorControl.updateOptions(this.getCodeEditorOptions());
}
}
private onThemeChanged(): void {
this.editorControl.updateOptions(this.getCodeEditorOptions());
}
protected getCodeEditorOptions(): IEditorOptions {
let baseOptions: IEditorOptions = {
overviewRulerLanes: 3,
@ -150,6 +157,7 @@ export abstract class BaseTextEditor extends BaseEditor {
// Pass on to Editor
if (visible) {
this.consumePendingConfigurationChangeEvent();
this.editorControl.onVisible();
} else {
this.editorControl.onHide();