@@ -435,19 +435,15 @@ export function SearchOverlay({
435435 let pressedGroupId = searchEventGroupId
436436 let pressedOnContext = ''
437437
438+ // When enter is pressed and no option is manually selected (-1), perform an AI search with the user input
438439 if ( selectedIndex === - 1 ) {
439440 if ( isAskAIState ) {
440441 pressedOnContext = AI_SEARCH_CONTEXT
441442 pressedGroupKey = ASK_AI_EVENT_GROUP
442443 pressedGroupId = askAIEventGroupId
443- // When we are in the Ask AI state, we want to ask another AI Search query
444- aiSearchOptionOnSelect ( { term : urlSearchInputQuery } as AutocompleteSearchHit )
445- } else if ( generalSearchResults . length > 0 ) {
446- pressedOnContext = GENERAL_SEARCH_CONTEXT
447- // Nothing manually selected, so general search the typed suggestion
448- performGeneralSearch ( )
449444 }
450- return sendKeyboardEvent ( event . key , pressedOnContext , pressedGroupId , pressedGroupKey )
445+ sendKeyboardEvent ( event . key , pressedOnContext , pressedGroupId , pressedGroupKey )
446+ aiSearchOptionOnSelect ( { term : urlSearchInputQuery } as AutocompleteSearchHit )
451447 }
452448
453449 if (
@@ -456,28 +452,30 @@ export function SearchOverlay({
456452 selectedIndex < combinedOptions . length
457453 ) {
458454 const selectedItem = combinedOptions [ selectedIndex ]
455+ let action = ( ) => { } // Execute the action after we send the event
459456 if ( selectedItem . group === 'general' ) {
460457 if (
461458 ( selectedItem . option as GeneralSearchHitWithOptions ) . isViewAllResults ||
462459 ( selectedItem . option as GeneralSearchHitWithOptions ) . isSearchDocsOption
463460 ) {
464461 pressedOnContext = 'view-all'
465- performGeneralSearch ( )
462+ action = performGeneralSearch
466463 } else {
467464 pressedOnContext = 'general-option'
468- generalSearchResultOnSelect ( selectedItem . option as GeneralSearchHit )
465+ action = ( ) => generalSearchResultOnSelect ( selectedItem . option as GeneralSearchHit )
469466 }
470467 } else if ( selectedItem . group === 'ai' ) {
471468 pressedOnContext = 'ai-option'
472- aiSearchOptionOnSelect ( selectedItem . option as AutocompleteSearchHit )
469+ action = ( ) => aiSearchOptionOnSelect ( selectedItem . option as AutocompleteSearchHit )
473470 } else if ( selectedItem . group === 'reference' ) {
474471 // On a reference select, we are in the Ask AI State / Screen
475472 pressedGroupKey = ASK_AI_EVENT_GROUP
476473 pressedGroupId = askAIEventGroupId
477474 pressedOnContext = 'reference-option'
478- referenceOnSelect ( selectedItem . url || '' )
475+ action = ( ) => referenceOnSelect ( selectedItem . url || '' )
479476 }
480477 sendKeyboardEvent ( event . key , pressedOnContext , pressedGroupId , pressedGroupKey )
478+ return action ( )
481479 }
482480 } else if ( event . key === 'Escape' ) {
483481 event . preventDefault ( )
0 commit comments