提交 9f5fd606 编写于 作者: A Alex Dima

Fixes Microsoft/monaco-editor#334: Forward standalone editor options to configuration service

上级 e67edc80
...@@ -700,4 +700,24 @@ const editorConfiguration: IConfigurationNode = { ...@@ -700,4 +700,24 @@ const editorConfiguration: IConfigurationNode = {
} }
}; };
let cachedEditorConfigurationKeys: { [key: string]: boolean; } = null;
function getEditorConfigurationKeys(): { [key: string]: boolean; } {
if (cachedEditorConfigurationKeys === null) {
cachedEditorConfigurationKeys = Object.create(null);
Object.keys(editorConfiguration.properties).forEach((prop) => {
cachedEditorConfigurationKeys[prop] = true;
});
}
return cachedEditorConfigurationKeys;
}
export function isEditorConfigurationKey(key: string): boolean {
const editorConfigurationKeys = getEditorConfigurationKeys();
return (editorConfigurationKeys[`editor.${key}`] || false);
}
export function isDiffEditorConfigurationKey(key: string): boolean {
const editorConfigurationKeys = getEditorConfigurationKeys();
return (editorConfigurationKeys[`diffEditor.${key}`] || false);
}
configurationRegistry.registerConfiguration(editorConfiguration); configurationRegistry.registerConfiguration(editorConfiguration);
...@@ -41,6 +41,7 @@ import { ITextModel } from 'vs/editor/common/model'; ...@@ -41,6 +41,7 @@ import { ITextModel } from 'vs/editor/common/model';
import { INotificationService, INotification, INotificationHandle, NoOpNotification, IPromptChoice } from 'vs/platform/notification/common/notification'; import { INotificationService, INotification, INotificationHandle, NoOpNotification, IPromptChoice } from 'vs/platform/notification/common/notification';
import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions } from 'vs/platform/dialogs/common/dialogs'; import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { IPosition, Position as Pos } from 'vs/editor/common/core/position'; import { IPosition, Position as Pos } from 'vs/editor/common/core/position';
import { isEditorConfigurationKey, isDiffEditorConfigurationKey } from 'vs/editor/common/config/commonEditorConfig';
export class SimpleEditor implements IEditor { export class SimpleEditor implements IEditor {
...@@ -495,6 +496,7 @@ export class SimpleConfigurationService implements IConfigurationService { ...@@ -495,6 +496,7 @@ export class SimpleConfigurationService implements IConfigurationService {
} }
public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> { public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> {
this.configuration().updateValue(key, value);
return TPromise.as(null); return TPromise.as(null);
} }
...@@ -620,3 +622,20 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService { ...@@ -620,3 +622,20 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService {
return true; return true;
} }
} }
export function applyConfigurationValues(configurationService: IConfigurationService, source: any, isDiffEditor: boolean): void {
if (!source) {
return;
}
if (!(configurationService instanceof SimpleConfigurationService)) {
return;
}
Object.keys(source).forEach((key) => {
if (isEditorConfigurationKey(key)) {
configurationService.updateValue(`editor.${key}`, source[key]);
}
if (isDiffEditor && isDiffEditorConfigurationKey(key)) {
configurationService.updateValue(`diffEditor.${key}`, source[key]);
}
});
}
...@@ -16,7 +16,7 @@ import { IModelChangedEvent } from 'vs/editor/common/editorCommon'; ...@@ -16,7 +16,7 @@ import { IModelChangedEvent } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model'; import { ITextModel } from 'vs/editor/common/model';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { StandaloneKeybindingService } from 'vs/editor/standalone/browser/simpleServices'; import { StandaloneKeybindingService, applyConfigurationValues } from 'vs/editor/standalone/browser/simpleServices';
import { IEditorContextViewService } from 'vs/editor/standalone/browser/standaloneServices'; import { IEditorContextViewService } from 'vs/editor/standalone/browser/standaloneServices';
import { CodeEditor } from 'vs/editor/browser/codeEditor'; import { CodeEditor } from 'vs/editor/browser/codeEditor';
import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
...@@ -30,6 +30,7 @@ import * as aria from 'vs/base/browser/ui/aria/aria'; ...@@ -30,6 +30,7 @@ import * as aria from 'vs/base/browser/ui/aria/aria';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import * as browser from 'vs/base/browser/browser'; import * as browser from 'vs/base/browser/browser';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
/** /**
* Description of an action contribution * Description of an action contribution
...@@ -284,6 +285,7 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE ...@@ -284,6 +285,7 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor { export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor {
private _contextViewService: IEditorContextViewService; private _contextViewService: IEditorContextViewService;
private readonly _configurationService: IConfigurationService;
private _ownsModel: boolean; private _ownsModel: boolean;
constructor( constructor(
...@@ -298,7 +300,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon ...@@ -298,7 +300,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
@IContextViewService contextViewService: IContextViewService, @IContextViewService contextViewService: IContextViewService,
@IStandaloneThemeService themeService: IStandaloneThemeService, @IStandaloneThemeService themeService: IStandaloneThemeService,
@INotificationService notificationService: INotificationService, @INotificationService notificationService: INotificationService,
@IConfigurationService configurationService: IConfigurationService
) { ) {
applyConfigurationValues(configurationService, options, false);
options = options || {}; options = options || {};
if (typeof options.theme === 'string') { if (typeof options.theme === 'string') {
themeService.setTheme(options.theme); themeService.setTheme(options.theme);
...@@ -308,6 +312,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon ...@@ -308,6 +312,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService); super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService);
this._contextViewService = <IEditorContextViewService>contextViewService; this._contextViewService = <IEditorContextViewService>contextViewService;
this._configurationService = configurationService;
this._register(toDispose); this._register(toDispose);
if (typeof model === 'undefined') { if (typeof model === 'undefined') {
...@@ -331,6 +336,11 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon ...@@ -331,6 +336,11 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
super.dispose(); super.dispose();
} }
public updateOptions(newOptions: IEditorOptions): void {
applyConfigurationValues(this._configurationService, newOptions, false);
super.updateOptions(newOptions);
}
_attachModel(model: ITextModel): void { _attachModel(model: ITextModel): void {
super._attachModel(model); super._attachModel(model);
if (this._view) { if (this._view) {
...@@ -350,6 +360,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon ...@@ -350,6 +360,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor { export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor {
private _contextViewService: IEditorContextViewService; private _contextViewService: IEditorContextViewService;
private readonly _configurationService: IConfigurationService;
constructor( constructor(
domElement: HTMLElement, domElement: HTMLElement,
...@@ -362,8 +373,10 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon ...@@ -362,8 +373,10 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
@IEditorWorkerService editorWorkerService: IEditorWorkerService, @IEditorWorkerService editorWorkerService: IEditorWorkerService,
@ICodeEditorService codeEditorService: ICodeEditorService, @ICodeEditorService codeEditorService: ICodeEditorService,
@IStandaloneThemeService themeService: IStandaloneThemeService, @IStandaloneThemeService themeService: IStandaloneThemeService,
@INotificationService notificationService: INotificationService @INotificationService notificationService: INotificationService,
@IConfigurationService configurationService: IConfigurationService
) { ) {
applyConfigurationValues(configurationService, options, true);
options = options || {}; options = options || {};
if (typeof options.theme === 'string') { if (typeof options.theme === 'string') {
options.theme = themeService.setTheme(options.theme); options.theme = themeService.setTheme(options.theme);
...@@ -372,6 +385,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon ...@@ -372,6 +385,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
super(domElement, options, editorWorkerService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService); super(domElement, options, editorWorkerService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService);
this._contextViewService = <IEditorContextViewService>contextViewService; this._contextViewService = <IEditorContextViewService>contextViewService;
this._configurationService = configurationService;
this._register(toDispose); this._register(toDispose);
...@@ -382,6 +396,11 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon ...@@ -382,6 +396,11 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
super.dispose(); super.dispose();
} }
public updateOptions(newOptions: IDiffEditorOptions): void {
applyConfigurationValues(this._configurationService, newOptions, true);
super.updateOptions(newOptions);
}
protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditor { protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditor {
return instantiationService.createInstance(StandaloneCodeEditor, container, options); return instantiationService.createInstance(StandaloneCodeEditor, container, options);
} }
......
...@@ -38,6 +38,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions'; ...@@ -38,6 +38,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { ITextModel, OverviewRulerLane, EndOfLinePreference, DefaultEndOfLine, EndOfLineSequence, TrackedRangeStickiness, TextModelResolvedOptions, FindMatch } from 'vs/editor/common/model'; import { ITextModel, OverviewRulerLane, EndOfLinePreference, DefaultEndOfLine, EndOfLineSequence, TrackedRangeStickiness, TextModelResolvedOptions, FindMatch } from 'vs/editor/common/model';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: HTMLElement, override: IEditorOverrideServices, callback: (services: DynamicStandaloneServices) => T): T { function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: HTMLElement, override: IEditorOverrideServices, callback: (services: DynamicStandaloneServices) => T): T {
let services = new DynamicStandaloneServices(domElement, override); let services = new DynamicStandaloneServices(domElement, override);
...@@ -90,7 +91,8 @@ export function create(domElement: HTMLElement, options?: IEditorConstructionOpt ...@@ -90,7 +91,8 @@ export function create(domElement: HTMLElement, options?: IEditorConstructionOpt
services.get(IKeybindingService), services.get(IKeybindingService),
services.get(IContextViewService), services.get(IContextViewService),
services.get(IStandaloneThemeService), services.get(IStandaloneThemeService),
services.get(INotificationService) services.get(INotificationService),
services.get(IConfigurationService),
); );
}); });
} }
...@@ -124,7 +126,8 @@ export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorC ...@@ -124,7 +126,8 @@ export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorC
services.get(IEditorWorkerService), services.get(IEditorWorkerService),
services.get(ICodeEditorService), services.get(ICodeEditorService),
services.get(IStandaloneThemeService), services.get(IStandaloneThemeService),
services.get(INotificationService) services.get(INotificationService),
services.get(IConfigurationService),
); );
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册