Skip to content

Commit 69d1e30

Browse files
EbonsignoriashishkeshanCopilot
authored
make AI Search default on enter (#55050)
Co-authored-by: Ashish Keshan <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a0ee8e2 commit 69d1e30

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/fixtures/tests/playwright-rendering.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ test('open new search, and perform a general search', async ({ page }) => {
8686
// NOTE: In the UI we wait for results to load before allowing "enter", because we don't want
8787
// to allow an unnecessary request when there are no search results. Easier to wait 1 second
8888
await page.waitForTimeout(1000)
89-
// Press enter to perform general search
90-
await page.keyboard.press('Enter')
89+
// Scroll down to "View all results" then press enter
90+
await page.getByText('View more results').click()
9191

9292
await expect(page).toHaveURL(
9393
/\/search\?search-overlay-input=serve\+playwright&query=serve\+playwright/,

src/search/components/helpers/execute-search-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function executeGeneralSearch(
4242
params.delete('search-overlay-open')
4343
}
4444
asPath += `?${params}`
45-
router.push(asPath)
45+
router.push(asPath, undefined, { shallow: false })
4646
}
4747

4848
export async function executeAISearch(

src/search/components/input/SearchOverlay.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)