@@ -258,36 +258,35 @@ private void ClickablePath_GettingFocus(UIElement sender, GettingFocusEventArgs
258258
259259 private async void Omnibar_QuerySubmitted ( Omnibar sender , OmnibarQuerySubmittedEventArgs args )
260260 {
261- if ( Omnibar . CurrentSelectedMode == OmnibarPathMode )
261+ var mode = Omnibar . CurrentSelectedMode ;
262+
263+ // Path mode
264+ if ( mode == OmnibarPathMode )
262265 {
263266 await ViewModel . HandleItemNavigationAsync ( args . Text ) ;
264267 ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
268+ return ;
265269 }
266- else if ( Omnibar . CurrentSelectedMode == OmnibarCommandPaletteMode )
270+
271+ // Command palette mode
272+ if ( mode == OmnibarCommandPaletteMode )
267273 {
268- if ( args . Item is not NavigationBarSuggestionItem item )
269- return ;
274+ var item = args . Item as NavigationBarSuggestionItem ;
270275
271276 // Try invoking built-in command
272- foreach ( IRichCommand command in Commands )
277+ foreach ( var command in Commands )
273278 {
274- if ( item . Text == command . Description )
275- {
276- if ( command == Commands . None )
277- await DialogDisplayHelper . ShowDialogAsync ( Strings . InvalidCommand . GetLocalizedResource ( ) ,
278- string . Format ( Strings . InvalidCommandContent . GetLocalizedResource ( ) , command . Code ) ) ;
279- else if ( ! command . IsExecutable )
280- await DialogDisplayHelper . ShowDialogAsync ( Strings . CommandNotExecutable . GetLocalizedResource ( ) ,
281- string . Format ( Strings . CommandNotExecutableContent . GetLocalizedResource ( ) , command . Code ) ) ;
282- else
283- await command . ExecuteAsync ( ) ;
279+ if ( ! string . Equals ( command . Description , item ? . Text , StringComparison . OrdinalIgnoreCase ) &&
280+ ! string . Equals ( command . Description , args . Text , StringComparison . OrdinalIgnoreCase ) )
281+ continue ;
284282
285- return ;
286- }
283+ await command . ExecuteAsync ( ) ;
284+ ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
285+ return ;
287286 }
288287
289288 // Try invoking Windows app action
290- if ( ActionManager . Instance . ActionRuntime is not null && item . ActionInstance is ActionInstance actionInstance )
289+ if ( ActionManager . Instance . ActionRuntime is not null && item ? . ActionInstance is ActionInstance actionInstance )
291290 {
292291 // Workaround for https://github.com/microsoft/App-Actions-On-Windows-Samples/issues/7
293292 var action = ActionManager . Instance . ActionRuntime . ActionCatalog . GetAllActions ( )
@@ -298,11 +297,17 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.CommandNotExecutable.GetLocali
298297 var overload = action . GetOverloads ( ) . FirstOrDefault ( ) ;
299298 await overload ? . InvokeAsync ( actionInstance . Context ) ;
300299 }
300+
301+ ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
302+ return ;
301303 }
302304
303- ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
305+ await DialogDisplayHelper . ShowDialogAsync ( Strings . InvalidCommand . GetLocalizedResource ( ) ,
306+ string . Format ( Strings . InvalidCommandContent . GetLocalizedResource ( ) , args . Text ) ) ;
304307 }
305- else if ( Omnibar . CurrentSelectedMode == OmnibarSearchMode )
308+
309+ // Search mode
310+ if ( Omnibar . CurrentSelectedMode == OmnibarSearchMode )
306311 {
307312 }
308313 }
0 commit comments