@@ -517,6 +517,7 @@ const totalSelectableCount = computed(() => suggestionCount.value + resultCount.
517517
518518/** Unified selected index: negative for suggestions, 0+ for packages */
519519const unifiedSelectedIndex = ref (0 )
520+ const userHasNavigated = ref (false )
520521
521522/** Convert unified index to suggestion index (0-based) or null */
522523function toSuggestionIndex(unified : number ): number | null {
@@ -552,6 +553,8 @@ watch(unifiedSelectedIndex, unified => {
552553watch (
553554 [visibleResults , validatedSuggestions , exactMatchType ],
554555 () => {
556+ if (userHasNavigated .value ) return
557+
555558 if (exactMatchType .value === ' package' ) {
556559 // Find the exact match package index
557560 const q = query .value .trim ().toLowerCase ()
@@ -584,8 +587,9 @@ watch(
584587 { immediate: true },
585588)
586589
587- // Reset selection when query changes
590+ // Reset selection and navigation flag when query changes
588591watch (query , () => {
592+ userHasNavigated .value = false
589593 // Will be re-initialized by the watch above when results load
590594 unifiedSelectedIndex .value = 0
591595})
@@ -622,6 +626,7 @@ function handleResultsKeydown(e: KeyboardEvent) {
622626
623627 if (e .key === ' ArrowDown' ) {
624628 e .preventDefault ()
629+ userHasNavigated .value = true
625630 unifiedSelectedIndex .value = clampUnifiedIndex (unifiedSelectedIndex .value + 1 )
626631 if (isFromInput ) {
627632 scrollToSelectedItem ()
@@ -633,6 +638,7 @@ function handleResultsKeydown(e: KeyboardEvent) {
633638
634639 if (e .key === ' ArrowUp' ) {
635640 e .preventDefault ()
641+ userHasNavigated .value = true
636642 unifiedSelectedIndex .value = clampUnifiedIndex (unifiedSelectedIndex .value - 1 )
637643 if (isFromInput ) {
638644 scrollToSelectedItem ()
0 commit comments