@@ -12,9 +12,10 @@ import * as labels from 'vs/base/common/labels';
1212import { Registry } from 'vs/platform/platform' ;
1313import { Action } from 'vs/base/common/actions' ;
1414import * as strings from 'vs/base/common/strings' ;
15+ import Event , { Emitter } from 'vs/base/common/event' ;
1516import { LinkedMap as Map } from 'vs/base/common/map' ;
1617import { IWorkbenchActionRegistry , Extensions } from 'vs/workbench/common/actionRegistry' ;
17- import { IEditorRegistry , Extensions as EditorExtensions } from 'vs/workbench/common/editor' ;
18+ import { IEditorRegistry , Extensions as EditorExtensions , EditorOptions } from 'vs/workbench/common/editor' ;
1819import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor' ;
1920import { StringEditorInput } from 'vs/workbench/common/editor/stringEditorInput' ;
2021import { ICommonCodeEditor , IEditorViewState } from 'vs/editor/common/editorCommon' ;
@@ -242,6 +243,9 @@ class DefaultSettingsInput extends StringEditorInput {
242243 static RESOURCE : URI = URI . from ( { scheme : network . Schemas . vscode , authority : 'defaultsettings' , path : '/settings.json' } ) ; // URI is used to register JSON schema support
243244 private static INSTANCE : DefaultSettingsInput ;
244245
246+ private _willDispose = new Emitter < void > ( ) ;
247+ public willDispose : Event < void > = this . _willDispose . event ;
248+
245249 public static getInstance ( instantiationService : IInstantiationService , configurationService : IWorkspaceConfigurationService ) : DefaultSettingsInput {
246250 if ( ! DefaultSettingsInput . INSTANCE ) {
247251 const editorConfig = configurationService . getConfiguration < any > ( ) ;
@@ -258,6 +262,12 @@ class DefaultSettingsInput extends StringEditorInput {
258262 protected getResource ( ) : URI {
259263 return DefaultSettingsInput . RESOURCE ;
260264 }
265+
266+ public dispose ( ) {
267+ this . _willDispose . fire ( ) ;
268+ this . _willDispose . dispose ( ) ;
269+ super . dispose ( ) ;
270+ }
261271}
262272
263273class DefaultKeybindingsInput extends StringEditorInput {
@@ -285,6 +295,8 @@ export class DefaultSettingsEditor extends StringEditor {
285295
286296 private static VIEW_STATE : Map < URI , IEditorViewState > = new Map < URI , IEditorViewState > ( ) ;
287297
298+ private inputDisposeListener ;
299+
288300 constructor (
289301 @ITelemetryService telemetryService : ITelemetryService ,
290302 @IInstantiationService instantiationService : IInstantiationService ,
@@ -306,8 +318,16 @@ export class DefaultSettingsEditor extends StringEditor {
306318 return DefaultSettingsEditor . ID ;
307319 }
308320
321+ public setInput ( input : EditorInput , options : EditorOptions ) : TPromise < void > {
322+ this . listenToInput ( input ) ;
323+ return super . setInput ( input , options ) ;
324+ }
325+
309326 public clearInput ( ) : void {
310327 this . saveState ( ) ;
328+ if ( this . inputDisposeListener ) {
329+ this . inputDisposeListener . dispose ( ) ;
330+ }
311331 super . clearInput ( ) ;
312332 }
313333
@@ -321,11 +341,14 @@ export class DefaultSettingsEditor extends StringEditor {
321341 }
322342
323343 private saveState ( ) {
324- const resource = this . getResource ( ) ;
325- if ( DefaultSettingsEditor . VIEW_STATE . has ( resource ) ) {
326- DefaultSettingsEditor . VIEW_STATE . delete ( resource ) ;
344+ const state = this . getControl ( ) . saveViewState ( ) ;
345+ if ( state ) {
346+ const resource = this . getResource ( ) ;
347+ if ( DefaultSettingsEditor . VIEW_STATE . has ( resource ) ) {
348+ DefaultSettingsEditor . VIEW_STATE . delete ( resource ) ;
349+ }
350+ DefaultSettingsEditor . VIEW_STATE . set ( resource , state ) ;
327351 }
328- DefaultSettingsEditor . VIEW_STATE . set ( resource , this . getControl ( ) . saveViewState ( ) ) ;
329352 }
330353
331354 private getResource ( ) : URI {
@@ -336,6 +359,15 @@ export class DefaultSettingsEditor extends StringEditor {
336359 const foldingController = ( < ICommonCodeEditor > this . getControl ( ) ) . getContribution < IFoldingController > ( FoldingContributionId ) ;
337360 foldingController . foldAll ( ) ;
338361 }
362+
363+ private listenToInput ( input : EditorInput ) {
364+ if ( this . inputDisposeListener ) {
365+ this . inputDisposeListener . dispose ( ) ;
366+ }
367+ if ( input instanceof DefaultSettingsInput ) {
368+ this . inputDisposeListener = input . willDispose ( ( ) => this . saveState ( ) ) ;
369+ }
370+ }
339371}
340372
341373( < IEditorRegistry > Registry . as ( EditorExtensions . Editors ) ) . registerEditor (
0 commit comments