@@ -435,19 +435,15 @@ export function SearchOverlay({
435
435
let pressedGroupId = searchEventGroupId
436
436
let pressedOnContext = ''
437
437
438
+ // When enter is pressed and no option is manually selected (-1), perform an AI search with the user input
438
439
if ( selectedIndex === - 1 ) {
439
440
if ( isAskAIState ) {
440
441
pressedOnContext = AI_SEARCH_CONTEXT
441
442
pressedGroupKey = ASK_AI_EVENT_GROUP
442
443
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 ( )
449
444
}
450
- return sendKeyboardEvent ( event . key , pressedOnContext , pressedGroupId , pressedGroupKey )
445
+ sendKeyboardEvent ( event . key , pressedOnContext , pressedGroupId , pressedGroupKey )
446
+ aiSearchOptionOnSelect ( { term : urlSearchInputQuery } as AutocompleteSearchHit )
451
447
}
452
448
453
449
if (
@@ -456,28 +452,30 @@ export function SearchOverlay({
456
452
selectedIndex < combinedOptions . length
457
453
) {
458
454
const selectedItem = combinedOptions [ selectedIndex ]
455
+ let action = ( ) => { } // Execute the action after we send the event
459
456
if ( selectedItem . group === 'general' ) {
460
457
if (
461
458
( selectedItem . option as GeneralSearchHitWithOptions ) . isViewAllResults ||
462
459
( selectedItem . option as GeneralSearchHitWithOptions ) . isSearchDocsOption
463
460
) {
464
461
pressedOnContext = 'view-all'
465
- performGeneralSearch ( )
462
+ action = performGeneralSearch
466
463
} else {
467
464
pressedOnContext = 'general-option'
468
- generalSearchResultOnSelect ( selectedItem . option as GeneralSearchHit )
465
+ action = ( ) => generalSearchResultOnSelect ( selectedItem . option as GeneralSearchHit )
469
466
}
470
467
} else if ( selectedItem . group === 'ai' ) {
471
468
pressedOnContext = 'ai-option'
472
- aiSearchOptionOnSelect ( selectedItem . option as AutocompleteSearchHit )
469
+ action = ( ) => aiSearchOptionOnSelect ( selectedItem . option as AutocompleteSearchHit )
473
470
} else if ( selectedItem . group === 'reference' ) {
474
471
// On a reference select, we are in the Ask AI State / Screen
475
472
pressedGroupKey = ASK_AI_EVENT_GROUP
476
473
pressedGroupId = askAIEventGroupId
477
474
pressedOnContext = 'reference-option'
478
- referenceOnSelect ( selectedItem . url || '' )
475
+ action = ( ) => referenceOnSelect ( selectedItem . url || '' )
479
476
}
480
477
sendKeyboardEvent ( event . key , pressedOnContext , pressedGroupId , pressedGroupKey )
478
+ return action ( )
481
479
}
482
480
} else if ( event . key === 'Escape' ) {
483
481
event . preventDefault ( )
0 commit comments