Skip to content

Commit c6ab0a4

Browse files
committed
fix: enter logic fix on Compare page
1 parent 5c60ee5 commit c6ab0a4

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

app/components/Compare/PackageSelector.vue

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,44 @@ function removePackage(name: string) {
116116
}
117117
118118
function handleKeydown(e: KeyboardEvent) {
119-
if (!keyboardShortcuts.value) {
119+
const items = navigableItems.value
120+
const count = items.length
121+
122+
if (e.key === 'Enter') {
123+
const inputValueTrim = inputValue.value.trim()
124+
if (!inputValueTrim) return
125+
126+
e.preventDefault()
127+
128+
// When instant search is off, first Enter commits the query to trigger search
129+
if (!settings.value.instantSearch && committedInput.value !== inputValueTrim) {
130+
committedInput.value = inputValueTrim
131+
return
132+
}
133+
134+
// If an item is highlighted, select it
135+
if (highlightedIndex.value >= 0 && highlightedIndex.value < count) {
136+
addPackage(items[highlightedIndex.value]!.name)
137+
return
138+
}
139+
140+
// Fallback: exact match or easter egg (preserves existing behavior)
141+
if (showNoDependencyOption.value) {
142+
addPackage(NO_DEPENDENCY_ID)
143+
} else {
144+
const hasMatch = filteredResults.value.find(r => r.name === inputValueTrim)
145+
if (hasMatch) {
146+
addPackage(inputValueTrim)
147+
}
148+
}
149+
120150
return
121151
}
122152
123-
const items = navigableItems.value
124-
const count = items.length
153+
// If keyboard shortcuts are disabled - do not handle other keys
154+
if (!keyboardShortcuts.value) {
155+
return
156+
}
125157
126158
switch (e.key) {
127159
case 'ArrowDown':
@@ -160,36 +192,6 @@ function handleKeydown(e: KeyboardEvent) {
160192
highlightedIndex.value = Math.max(highlightedIndex.value - PAGE_JUMP, 0)
161193
break
162194
163-
case 'Enter': {
164-
const inputValueTrim = inputValue.value.trim()
165-
if (!inputValueTrim) return
166-
167-
e.preventDefault()
168-
169-
// When instant search is off, first Enter commits the query to trigger search
170-
if (!settings.value.instantSearch && committedInput.value !== inputValueTrim) {
171-
committedInput.value = inputValueTrim
172-
return
173-
}
174-
175-
// If an item is highlighted, select it
176-
if (highlightedIndex.value >= 0 && highlightedIndex.value < count) {
177-
addPackage(items[highlightedIndex.value]!.name)
178-
return
179-
}
180-
181-
// Fallback: exact match or easter egg (preserves existing behavior)
182-
if (showNoDependencyOption.value) {
183-
addPackage(NO_DEPENDENCY_ID)
184-
} else {
185-
const hasMatch = filteredResults.value.find(r => r.name === inputValueTrim)
186-
if (hasMatch) {
187-
addPackage(inputValueTrim)
188-
}
189-
}
190-
break
191-
}
192-
193195
case 'Escape':
194196
inputValue.value = ''
195197
highlightedIndex.value = -1

0 commit comments

Comments
 (0)