···541541 el.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
542542}
543543544544+// Navigate to package page
545545+async function navigateToPackage(packageName: string) {
546546+ await navigateTo({
547547+ name: 'package',
548548+ params: { package: packageName.split('/') },
549549+ })
550550+}
551551+552552+// Track the input value when user pressed Enter (for navigating when results arrive)
553553+const pendingEnterQuery = shallowRef<string | null>(null)
554554+555555+// Watch for results to navigate when Enter was pressed before results arrived
556556+watch(displayResults, results => {
557557+ if (!pendingEnterQuery.value) return
558558+559559+ // Check if input is still focused (user hasn't started navigating or clicked elsewhere)
560560+ if (document.activeElement?.tagName !== 'INPUT') {
561561+ pendingEnterQuery.value = null
562562+ return
563563+ }
564564+565565+ // Navigate if first result matches the query that was entered
566566+ const firstResult = results[0]
567567+ // eslint-disable-next-line no-console
568568+ console.log('[search] watcher fired', {
569569+ pending: pendingEnterQuery.value,
570570+ firstResult: firstResult?.package.name,
571571+ })
572572+ if (firstResult?.package.name === pendingEnterQuery.value) {
573573+ pendingEnterQuery.value = null
574574+ navigateToPackage(firstResult.package.name)
575575+ }
576576+})
577577+544578function handleResultsKeydown(e: KeyboardEvent) {
579579+ // If the active element is an input, navigate to exact match or wait for results
580580+ if (e.key === 'Enter' && document.activeElement?.tagName === 'INPUT') {
581581+ // Get value directly from input (not from route query, which may be debounced)
582582+ const inputValue = (document.activeElement as HTMLInputElement).value.trim()
583583+ if (!inputValue) return
584584+585585+ // Check if first result matches the input value exactly
586586+ const firstResult = displayResults.value[0]
587587+ if (firstResult?.package.name === inputValue) {
588588+ pendingEnterQuery.value = null
589589+ return navigateToPackage(firstResult.package.name)
590590+ }
591591+592592+ // No match yet - store input value, watcher will handle navigation when results arrive
593593+ pendingEnterQuery.value = inputValue
594594+ return
595595+ }
596596+545597 if (totalSelectableCount.value <= 0) return
546598547599 const elements = getFocusableElements()