@@ -258,32 +258,38 @@ 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+ else 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- if ( item . Text is { } commandText )
277+ foreach ( var command in Commands )
273278 {
274- var command = Commands [ commandText ] ;
275279 if ( command == Commands . None )
276- await DialogDisplayHelper . ShowDialogAsync ( Strings . InvalidCommand . GetLocalizedResource ( ) ,
277- string . Format ( Strings . InvalidCommandContent . GetLocalizedResource ( ) , commandText ) ) ;
278- else if ( ! command . IsExecutable )
279- await DialogDisplayHelper . ShowDialogAsync ( Strings . CommandNotExecutable . GetLocalizedResource ( ) ,
280- string . Format ( Strings . CommandNotExecutableContent . GetLocalizedResource ( ) , command . Code ) ) ;
281- else
282- await command . ExecuteAsync ( ) ;
280+ continue ;
281+
282+ if ( ! string . Equals ( command . Description , item ? . Text , StringComparison . OrdinalIgnoreCase ) &&
283+ ! string . Equals ( command . Description , args . Text , StringComparison . OrdinalIgnoreCase ) )
284+ continue ;
285+
286+ await command . ExecuteAsync ( ) ;
287+ ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
288+ return ;
283289 }
284290
285291 // Try invoking Windows app action
286- else if ( ActionManager . Instance . ActionRuntime is not null && item . ActionInstance is ActionInstance actionInstance )
292+ if ( ActionManager . Instance . ActionRuntime is not null && item ? . ActionInstance is ActionInstance actionInstance )
287293 {
288294 // Workaround for https://github.com/microsoft/App-Actions-On-Windows-Samples/issues/7
289295 var action = ActionManager . Instance . ActionRuntime . ActionCatalog . GetAllActions ( )
@@ -294,11 +300,20 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.CommandNotExecutable.GetLocali
294300 var overload = action . GetOverloads ( ) . FirstOrDefault ( ) ;
295301 await overload ? . InvokeAsync ( actionInstance . Context ) ;
296302 }
303+
304+ ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
305+ return ;
297306 }
298307
308+ await DialogDisplayHelper . ShowDialogAsync ( Strings . InvalidCommand . GetLocalizedResource ( ) ,
309+ string . Format ( Strings . InvalidCommandContent . GetLocalizedResource ( ) , args . Text ) ) ;
310+
299311 ( MainPageViewModel . SelectedTabItem ? . TabItemContent as Control ) ? . Focus ( FocusState . Programmatic ) ;
312+ return ;
300313 }
301- else if ( Omnibar . CurrentSelectedMode == OmnibarSearchMode )
314+
315+ // Search mode
316+ else if ( mode == OmnibarSearchMode )
302317 {
303318 }
304319 }
0 commit comments