@@ -7,7 +7,7 @@ import * as DOM from 'vs/base/browser/dom';
77import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
88import { CancellationToken } from 'vs/base/common/cancellation' ;
99import { KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
10- import { assertIsDefined } from 'vs/base/common/types' ;
10+ import { assertIsDefined , withNullAsUndefined } from 'vs/base/common/types' ;
1111import { URI } from 'vs/base/common/uri' ;
1212import 'vs/css!./media/searchEditor' ;
1313import { CodeEditorWidget , ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget' ;
@@ -169,7 +169,7 @@ export class SearchEditor extends BaseEditor {
169169 }
170170 } ) ;
171171
172-
172+ this . _register ( this . onDidBlur ( ( ) => this . saveViewState ( ) ) ) ;
173173
174174 this . _register ( this . searchResultEditor . onKeyDown ( e => e . keyCode === KeyCode . Escape && this . queryEditorWidget . searchInput . focus ( ) ) ) ;
175175
@@ -183,6 +183,10 @@ export class SearchEditor extends BaseEditor {
183183 } ) ;
184184 }
185185
186+ focus ( ) {
187+ this . restoreViewState ( ) ;
188+ }
189+
186190 focusNextInput ( ) {
187191 if ( this . queryEditorWidget . searchInputHasFocus ( ) ) {
188192 if ( this . showingIncludesExcludes ) {
@@ -334,10 +338,6 @@ export class SearchEditor extends BaseEditor {
334338 this . reLayout ( ) ;
335339 }
336340
337- focusInput ( ) {
338- this . queryEditorWidget . focus ( ) ;
339- }
340-
341341 getSelected ( ) {
342342 const selection = this . searchResultEditor . getSelection ( ) ;
343343 if ( selection ) {
@@ -360,6 +360,8 @@ export class SearchEditor extends BaseEditor {
360360 }
361361
362362 async setInput ( newInput : SearchEditorInput , options : EditorOptions | undefined , token : CancellationToken ) : Promise < void > {
363+ this . saveViewState ( ) ;
364+
363365 await super . setInput ( newInput , options , token ) ;
364366 this . inSearchEditorContextKey . set ( true ) ;
365367
@@ -379,7 +381,7 @@ export class SearchEditor extends BaseEditor {
379381 this . inputPatternExcludes . setUseExcludesAndIgnoreFiles ( query . useIgnores ) ;
380382 this . toggleIncludesExcludes ( query . showIncludesExcludes ) ;
381383
382- this . focusInput ( ) ;
384+ this . restoreViewState ( ) ;
383385 this . pauseSearching = false ;
384386 }
385387
@@ -404,7 +406,30 @@ export class SearchEditor extends BaseEditor {
404406 return this . searchResultEditor . getModel ( ) ;
405407 }
406408
409+ private saveViewState ( ) {
410+ const input = this . getInput ( ) ;
411+ if ( ! input ) { return ; }
412+
413+ if ( this . searchResultEditor . hasWidgetFocus ( ) ) {
414+ const viewState = this . searchResultEditor . saveViewState ( ) ;
415+ input . viewState = { focused : 'editor' , state : assertIsDefined ( withNullAsUndefined ( viewState ) ) } ;
416+ } else {
417+ input . viewState = { focused : 'input' } ;
418+ }
419+ }
420+
421+ private restoreViewState ( ) {
422+ const input = this . getInput ( ) ;
423+ if ( input && input . viewState && input . viewState . focused === 'editor' ) {
424+ this . searchResultEditor . restoreViewState ( input . viewState . state ) ;
425+ this . searchResultEditor . focus ( ) ;
426+ } else {
427+ this . queryEditorWidget . focus ( ) ;
428+ }
429+ }
430+
407431 clearInput ( ) {
432+ this . saveViewState ( ) ;
408433 super . clearInput ( ) ;
409434 this . inSearchEditorContextKey . set ( false ) ;
410435 }
0 commit comments