Skip to content

Commit

Permalink
store pending config change event and 'replay' when becoming visible, f…
Browse files Browse the repository at this point in the history
…ixes #9892
  • Loading branch information
jrieken committed Jul 28, 2016
1 parent 89fbf8c commit e466584
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 54 deletions.
49 changes: 19 additions & 30 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

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;
}
// 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;
}

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);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/vs/editor/common/services/modeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/vs/editor/common/services/modeServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class ModeServiceImpl implements IModeService {
}
}

public configureAllModes(config:any): void {
protected _configureAllModes(config:any): void {
if (!config) {
return;
}
Expand Down Expand Up @@ -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 */);

Expand Down
3 changes: 0 additions & 3 deletions src/vs/editor/test/common/mocks/mockModeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
46 changes: 27 additions & 19 deletions src/vs/workbench/browser/parts/editor/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e466584

Please sign in to comment.