@@ -1035,6 +1035,18 @@ private void SavePathToHistory(string path)
10351035 UserSettingsService . GeneralSettingsService . PathHistoryList = pathHistoryList ;
10361036 }
10371037
1038+ public void SaveSearchQueryToList ( string searchQuery )
1039+ {
1040+ var previousSearchQueriesList = UserSettingsService . GeneralSettingsService . PreviousSearchQueriesList ? . ToList ( ) ?? [ ] ;
1041+ previousSearchQueriesList . Remove ( searchQuery ) ;
1042+ previousSearchQueriesList . Insert ( 0 , searchQuery ) ;
1043+
1044+ if ( previousSearchQueriesList . Count > MaxSuggestionsCount )
1045+ UserSettingsService . GeneralSettingsService . PreviousSearchQueriesList = previousSearchQueriesList . RemoveFrom ( MaxSuggestionsCount + 1 ) ;
1046+ else
1047+ UserSettingsService . GeneralSettingsService . PreviousSearchQueriesList = previousSearchQueriesList ;
1048+ }
1049+
10381050 private static async Task < bool > LaunchApplicationFromPath ( string currentInput , string workingDir )
10391051 {
10401052 var args = CommandLineParser . SplitArguments ( currentInput ) ;
@@ -1243,6 +1255,56 @@ public void PopulateOmnibarSuggestionsForCommandPaletteMode()
12431255 }
12441256 }
12451257
1258+ public async Task PopulateOmnibarSuggestionsForSearchMode ( )
1259+ {
1260+ if ( ContentPageContext . ShellPage is null )
1261+ return ;
1262+
1263+ List < SuggestionModel > newSuggestions = [ ] ;
1264+
1265+ if ( string . IsNullOrWhiteSpace ( OmnibarSearchModeText ) )
1266+ {
1267+ var previousSearchQueries = UserSettingsService . GeneralSettingsService . PreviousSearchQueriesList ;
1268+ if ( previousSearchQueries is not null )
1269+ {
1270+ newSuggestions . AddRange (
1271+ previousSearchQueries . Select ( query => new SuggestionModel ( query , true ) )
1272+ ) ;
1273+ }
1274+ }
1275+ else
1276+ {
1277+ var search = new FolderSearch
1278+ {
1279+ Query = OmnibarSearchModeText ,
1280+ Folder = ContentPageContext . ShellPage . ShellViewModel . WorkingDirectory ,
1281+ MaxItemCount = 10 ,
1282+ } ;
1283+
1284+ var results = await search . SearchAsync ( ) ;
1285+ newSuggestions . AddRange ( results . Select ( result => new SuggestionModel ( result ) ) ) ;
1286+ }
1287+
1288+ if ( newSuggestions . Count is 0 )
1289+ newSuggestions . Add ( new SuggestionModel ( Strings . NavigationToolbarVisiblePathNoResults . GetLocalizedResource ( ) , false ) ) ;
1290+
1291+ // Remove outdated suggestions
1292+ var toRemove = OmnibarSearchModeSuggestionItems
1293+ . Where ( existing => ! newSuggestions . Any ( newItem => newItem . ItemPath == existing . ItemPath ) )
1294+ . ToList ( ) ;
1295+
1296+ foreach ( var item in toRemove )
1297+ OmnibarSearchModeSuggestionItems . Remove ( item ) ;
1298+
1299+ // Add new suggestions
1300+ var toAdd = newSuggestions
1301+ . Where ( newItem => ! OmnibarSearchModeSuggestionItems . Any ( existing => existing . ItemPath == newItem . ItemPath ) ) ;
1302+
1303+ foreach ( var item in toAdd )
1304+ OmnibarSearchModeSuggestionItems . Add ( item ) ;
1305+ }
1306+
1307+
12461308 [ Obsolete ( "Remove once Omnibar goes out of experimental." ) ]
12471309 public async Task SetAddressBarSuggestionsAsync ( AutoSuggestBox sender , IShellPage shellpage )
12481310 {
0 commit comments