@@ -349,8 +349,9 @@ export class SettingsEditor2 extends EditorPane {
349
349
this . defaultSettingsEditorModel = model ;
350
350
351
351
options = options || validateSettingsEditorOptions ( { } ) ;
352
- if ( ! this . viewState . settingsTarget ) {
353
- if ( ! options . target ) {
352
+ if ( ! this . viewState . settingsTarget || ! this . settingsTargetsWidget . settingsTarget ) {
353
+ const optionsHasViewStateTarget = options . viewState && ( options . viewState as ISettingsEditorViewState ) . settingsTarget ;
354
+ if ( ! options . target && ! optionsHasViewStateTarget ) {
354
355
options . target = ConfigurationTarget . USER_LOCAL ;
355
356
}
356
357
}
@@ -387,6 +388,10 @@ export class SettingsEditor2 extends EditorPane {
387
388
return withUndefinedAsNull ( cachedState ) ;
388
389
}
389
390
391
+ override getViewState ( ) : object | undefined {
392
+ return this . viewState ;
393
+ }
394
+
390
395
override setOptions ( options : ISettingsEditorOptions | undefined ) : void {
391
396
super . setOptions ( options ) ;
392
397
@@ -401,11 +406,16 @@ export class SettingsEditor2 extends EditorPane {
401
406
this . focusSearch ( ) ;
402
407
}
403
408
404
- if ( options . query ) {
405
- this . searchWidget . setValue ( options . query ) ;
409
+ const recoveredViewState = options . viewState ?
410
+ options . viewState as ISettingsEditorViewState : undefined ;
411
+
412
+ const query : string | undefined = recoveredViewState ?. query ?? options . query ;
413
+ if ( query !== undefined ) {
414
+ this . searchWidget . setValue ( query ) ;
415
+ this . viewState . query = query ;
406
416
}
407
417
408
- const target : SettingsTarget = options . folderUri || < SettingsTarget > options . target ;
418
+ const target : SettingsTarget | undefined = options . folderUri ?? recoveredViewState ?. settingsTarget ?? < SettingsTarget | undefined > options . target ;
409
419
if ( target ) {
410
420
this . settingsTargetsWidget . settingsTarget = target ;
411
421
this . viewState . settingsTarget = target ;
@@ -1237,8 +1247,9 @@ export class SettingsEditor2 extends EditorPane {
1237
1247
this . settingsTreeModel . update ( resolvedSettingsRoot ) ;
1238
1248
this . tocTreeModel . settingsTreeRoot = this . settingsTreeModel . root as SettingsTreeGroupElement ;
1239
1249
1240
- const cachedState = this . restoreCachedState ( ) ;
1241
- if ( cachedState && cachedState . searchQuery || ! ! this . searchWidget . getValue ( ) ) {
1250
+ // Don't restore the cached state if we already have a query value from calling _setOptions().
1251
+ const cachedState = ! this . viewState . query ? this . restoreCachedState ( ) : undefined ;
1252
+ if ( cachedState ?. searchQuery || this . searchWidget . getValue ( ) ) {
1242
1253
await this . onSearchInputChanged ( ) ;
1243
1254
} else {
1244
1255
this . refreshTOCTree ( ) ;
@@ -1358,6 +1369,7 @@ export class SettingsEditor2 extends EditorPane {
1358
1369
}
1359
1370
1360
1371
const query = this . searchWidget . getValue ( ) . trim ( ) ;
1372
+ this . viewState . query = query ;
1361
1373
this . delayedFilterLogging . cancel ( ) ;
1362
1374
await this . triggerSearch ( query . replace ( / \u203A / g, ' ' ) ) ;
1363
1375
0 commit comments