@@ -99,11 +99,7 @@ export class TextFileEditor extends BaseTextEditor {
9999 // been disposed and we can safely persist the view state still as needed.
100100 this . _register ( ( group as IEditorGroupView ) . onWillCloseEditor ( e => {
101101 if ( e . editor === this . input ) {
102- if ( this . restoreViewState ) {
103- this . doSaveTextEditorViewState ( this . input ) ;
104- } else {
105- this . clearTextEditorViewState ( [ this . input . getResource ( ) ] , this . group ) ;
106- }
102+ this . doSaveOrClearTextEditorViewState ( this . input ) ;
107103 }
108104 } ) ) ;
109105 }
@@ -117,8 +113,8 @@ export class TextFileEditor extends BaseTextEditor {
117113
118114 setInput ( input : FileEditorInput , options : EditorOptions , token : CancellationToken ) : Thenable < void > {
119115
120- // Remember view settings if input changes
121- this . doSaveTextEditorViewState ( this . input ) ;
116+ // Update/clear view settings if input changes
117+ this . doSaveOrClearTextEditorViewState ( this . input ) ;
122118
123119 // Set input and resolve
124120 return super . setInput ( input , options , token ) . then ( ( ) => {
@@ -259,8 +255,8 @@ export class TextFileEditor extends BaseTextEditor {
259255
260256 clearInput ( ) : void {
261257
262- // Keep editor view state in settings to restore when coming back
263- this . doSaveTextEditorViewState ( this . input ) ;
258+ // Update/clear editor view state in settings
259+ this . doSaveOrClearTextEditorViewState ( this . input ) ;
264260
265261 // Clear Model
266262 this . getControl ( ) . setModel ( null ) ;
@@ -271,15 +267,26 @@ export class TextFileEditor extends BaseTextEditor {
271267
272268 shutdown ( ) : void {
273269
274- // Save View State
275- this . doSaveTextEditorViewState ( this . input ) ;
270+ // Update/clear editor view State
271+ this . doSaveOrClearTextEditorViewState ( this . input ) ;
276272
277273 // Call Super
278274 super . shutdown ( ) ;
279275 }
280276
281- private doSaveTextEditorViewState ( input : FileEditorInput ) : void {
282- if ( input && ! input . isDisposed ( ) ) {
277+ private doSaveOrClearTextEditorViewState ( input : FileEditorInput ) : void {
278+ if ( ! input ) {
279+ return ; // ensure we have an input to handle view state for
280+ }
281+
282+ // If the user configured to not restore view state, we clear the view
283+ // state unless the editor is still opened in the group.
284+ if ( ! this . restoreViewState && ( ! this . group || ! this . group . isOpened ( input ) ) ) {
285+ this . clearTextEditorViewState ( [ input . getResource ( ) ] , this . group ) ;
286+ }
287+
288+ // Otherwise we save the view state to restore it later
289+ else if ( ! input . isDisposed ( ) ) {
283290 this . saveTextEditorViewState ( input . getResource ( ) ) ;
284291 }
285292 }
0 commit comments