@@ -52,13 +52,14 @@ export class SearchEditorInput extends EditorInput {
5252
5353 private dirty : boolean = false ;
5454 private readonly model : Promise < ITextModel > ;
55- private resolvedModel ?: { model : ITextModel , query : SearchConfiguration } ;
55+ private query : Partial < SearchConfiguration > | undefined ;
56+
5657 viewState : SearchEditorViewState = { focused : 'input' } ;
57- _restoredName : string | undefined ;
5858
5959 constructor (
6060 public readonly resource : URI ,
6161 getModel : ( ) => Promise < ITextModel > ,
62+ startingConfig : Partial < SearchConfiguration > | undefined ,
6263 @IModelService private readonly modelService : IModelService ,
6364 @IEditorService protected readonly editorService : IEditorService ,
6465 @IEditorGroupsService protected readonly editorGroupService : IEditorGroupsService ,
@@ -87,6 +88,8 @@ export class SearchEditorInput extends EditorInput {
8788 } ;
8889
8990 this . workingCopyService . registerWorkingCopy ( workingCopyAdapter ) ;
91+
92+ this . query = startingConfig ;
9093 }
9194
9295 getResource ( ) {
@@ -123,10 +126,9 @@ export class SearchEditorInput extends EditorInput {
123126
124127 getName ( ) : string {
125128 if ( this . isUntitled ( ) ) {
126- return this . _restoredName ??
127- ( this . resolvedModel ?. query . query
128- ? localize ( 'searchTitle.withQuery' , "Search: {0}" , this . resolvedModel ?. query . query )
129- : localize ( 'searchTitle' , "Search" ) ) ;
129+ return ( this . query ?. query
130+ ? localize ( 'searchTitle.withQuery' , "Search: {0}" , this . query . query )
131+ : localize ( 'searchTitle' , "Search" ) ) ;
130132 }
131133
132134 return localize ( 'searchTitle.withQuery' , "Search: {0}" , basename ( this . resource . path , '.code-search' ) ) ;
@@ -135,18 +137,13 @@ export class SearchEditorInput extends EditorInput {
135137 async reloadModel ( ) {
136138 const model = await this . model ;
137139 const query = extractSearchQuery ( model ) ;
138- this . resolvedModel = { model, query } ;
139- this . _restoredName = undefined ; // not needed after the model has been resolved
140+ this . query = query ;
140141 this . _onDidChangeLabel . fire ( ) ;
141142 return { model, query } ;
142143 }
143144
144145 getConfigSync ( ) {
145- if ( ! this . resolvedModel ) {
146- console . error ( 'Requested config for Search Editor before initalization' ) ;
147- }
148-
149- return this . resolvedModel ?. query ;
146+ return this . query ;
150147 }
151148
152149 async resolve ( ) {
@@ -281,11 +278,10 @@ export class SearchEditorInputFactory implements IEditorInputFactory {
281278 }
282279
283280 deserialize ( instantiationService : IInstantiationService , serializedEditorInput : string ) : SearchEditorInput | undefined {
284- const { resource, dirty, config, viewState, name } = JSON . parse ( serializedEditorInput ) ;
281+ const { resource, dirty, config, viewState } = JSON . parse ( serializedEditorInput ) ;
285282 if ( config && ( config . query !== undefined ) ) {
286- const input = instantiationService . invokeFunction ( getOrMakeSearchEditorInput , { text : serializeSearchConfiguration ( config ) , uri : URI . parse ( resource ) } ) ;
283+ const input = instantiationService . invokeFunction ( getOrMakeSearchEditorInput , { config, uri : URI . parse ( resource ) } ) ;
287284 input . viewState = viewState ;
288- input . _restoredName = name ;
289285 input . setDirty ( dirty ) ;
290286 return input ;
291287 }
@@ -297,7 +293,10 @@ export class SearchEditorInputFactory implements IEditorInputFactory {
297293const inputs = new Map < string , SearchEditorInput > ( ) ;
298294export const getOrMakeSearchEditorInput = (
299295 accessor : ServicesAccessor ,
300- existingData : { uri : URI , text ?: string } | { text : string , uri ?: URI }
296+ existingData :
297+ { uri : URI , config ?: Partial < SearchConfiguration > , text ?: never } |
298+ { text : string , uri ?: never , config ?: never } |
299+ { config : Partial < SearchConfiguration > , text ?: never , uri ?: never }
301300) : SearchEditorInput => {
302301
303302 const uri = existingData . uri ?? URI . from ( { scheme : searchEditorScheme , fragment : `${ Math . random ( ) } ` } ) ;
@@ -313,6 +312,7 @@ export const getOrMakeSearchEditorInput = (
313312 return existing ;
314313 }
315314
315+ const config = existingData . config ?? ( existingData . text ? extractSearchQuery ( existingData . text ) : { } ) ;
316316
317317 const getModel = async ( ) => {
318318 const existing = modelService . getModel ( uri ) ;
@@ -328,12 +328,13 @@ export const getOrMakeSearchEditorInput = (
328328 } else if ( uri . scheme !== searchEditorScheme ) {
329329 contents = ( await textFileService . read ( uri ) ) . value ;
330330 } else {
331- contents = existingData . text ?? '' ;
331+ contents = existingData . text ??
332+ ( existingData . config ? serializeSearchConfiguration ( existingData . config ) : '' ) ;
332333 }
333334 return modelService . createModel ( contents , modeService . create ( 'search-result' ) , uri ) ;
334335 } ;
335336
336- const input = instantiationService . createInstance ( SearchEditorInput , uri , getModel ) ;
337+ const input = instantiationService . createInstance ( SearchEditorInput , uri , getModel , config ) ;
337338
338339 inputs . set ( uri . toString ( ) , input ) ;
339340 input . onDispose ( ( ) => inputs . delete ( uri . toString ( ) ) ) ;
0 commit comments