diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 70f7b4053ee7b2ae894525a9a7632be01012cc79..443d41634697a98f94ff66aa1ab77e1addd21ec7 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -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); diff --git a/src/vs/editor/standalone/browser/simpleServices.ts b/src/vs/editor/standalone/browser/simpleServices.ts index a09429f113755355848a0aea8013d7492072702d..4a3c0f43cb2558ce3ec5e873b9e212dec7c93e30 100644 --- a/src/vs/editor/standalone/browser/simpleServices.ts +++ b/src/vs/editor/standalone/browser/simpleServices.ts @@ -41,6 +41,7 @@ import { ITextModel } from 'vs/editor/common/model'; import { INotificationService, INotification, INotificationHandle, NoOpNotification, IPromptChoice } from 'vs/platform/notification/common/notification'; import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions } from 'vs/platform/dialogs/common/dialogs'; 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 { @@ -495,6 +496,7 @@ export class SimpleConfigurationService implements IConfigurationService { } public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise { + this.configuration().updateValue(key, value); return TPromise.as(null); } @@ -620,3 +622,20 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService { 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]); + } + }); +} diff --git a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts index 53a9a83ed47db4b1b2fc79d298cfcf8ae9fe9ddd..46b15a7bf8fc593eba1644487d7746cd769836e5 100644 --- a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts @@ -16,7 +16,7 @@ import { IModelChangedEvent } from 'vs/editor/common/editorCommon'; import { ITextModel } from 'vs/editor/common/model'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; 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 { CodeEditor } from 'vs/editor/browser/codeEditor'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; @@ -30,6 +30,7 @@ import * as aria from 'vs/base/browser/ui/aria/aria'; import * as nls from 'vs/nls'; import * as browser from 'vs/base/browser/browser'; import { INotificationService } from 'vs/platform/notification/common/notification'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; /** * Description of an action contribution @@ -284,6 +285,7 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor { private _contextViewService: IEditorContextViewService; + private readonly _configurationService: IConfigurationService; private _ownsModel: boolean; constructor( @@ -298,7 +300,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon @IContextViewService contextViewService: IContextViewService, @IStandaloneThemeService themeService: IStandaloneThemeService, @INotificationService notificationService: INotificationService, + @IConfigurationService configurationService: IConfigurationService ) { + applyConfigurationValues(configurationService, options, false); options = options || {}; if (typeof options.theme === 'string') { themeService.setTheme(options.theme); @@ -308,6 +312,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService); this._contextViewService = contextViewService; + this._configurationService = configurationService; this._register(toDispose); if (typeof model === 'undefined') { @@ -331,6 +336,11 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon super.dispose(); } + public updateOptions(newOptions: IEditorOptions): void { + applyConfigurationValues(this._configurationService, newOptions, false); + super.updateOptions(newOptions); + } + _attachModel(model: ITextModel): void { super._attachModel(model); if (this._view) { @@ -350,6 +360,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor { private _contextViewService: IEditorContextViewService; + private readonly _configurationService: IConfigurationService; constructor( domElement: HTMLElement, @@ -362,8 +373,10 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon @IEditorWorkerService editorWorkerService: IEditorWorkerService, @ICodeEditorService codeEditorService: ICodeEditorService, @IStandaloneThemeService themeService: IStandaloneThemeService, - @INotificationService notificationService: INotificationService + @INotificationService notificationService: INotificationService, + @IConfigurationService configurationService: IConfigurationService ) { + applyConfigurationValues(configurationService, options, true); options = options || {}; if (typeof options.theme === 'string') { options.theme = themeService.setTheme(options.theme); @@ -372,6 +385,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon super(domElement, options, editorWorkerService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService); this._contextViewService = contextViewService; + this._configurationService = configurationService; this._register(toDispose); @@ -382,6 +396,11 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon super.dispose(); } + public updateOptions(newOptions: IDiffEditorOptions): void { + applyConfigurationValues(this._configurationService, newOptions, true); + super.updateOptions(newOptions); + } + protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditor { return instantiationService.createInstance(StandaloneCodeEditor, container, options); } diff --git a/src/vs/editor/standalone/browser/standaloneEditor.ts b/src/vs/editor/standalone/browser/standaloneEditor.ts index f6fbf6ba71d9de12bfbff1ae02639eb53c4877f2..1612563d285e2d91fa5791da7747cefa8bc8b65c 100644 --- a/src/vs/editor/standalone/browser/standaloneEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneEditor.ts @@ -38,6 +38,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { ITextModel, OverviewRulerLane, EndOfLinePreference, DefaultEndOfLine, EndOfLineSequence, TrackedRangeStickiness, TextModelResolvedOptions, FindMatch } from 'vs/editor/common/model'; import { INotificationService } from 'vs/platform/notification/common/notification'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; function withAllStandaloneServices(domElement: HTMLElement, override: IEditorOverrideServices, callback: (services: DynamicStandaloneServices) => T): T { let services = new DynamicStandaloneServices(domElement, override); @@ -90,7 +91,8 @@ export function create(domElement: HTMLElement, options?: IEditorConstructionOpt services.get(IKeybindingService), services.get(IContextViewService), services.get(IStandaloneThemeService), - services.get(INotificationService) + services.get(INotificationService), + services.get(IConfigurationService), ); }); } @@ -124,7 +126,8 @@ export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorC services.get(IEditorWorkerService), services.get(ICodeEditorService), services.get(IStandaloneThemeService), - services.get(INotificationService) + services.get(INotificationService), + services.get(IConfigurationService), ); }); }