feat: enter key open the first package when searching#993
feat: enter key open the first package when searching#993danielroe merged 3 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughKeyboard-driven navigation for search results was added. A programmatic 🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
app/pages/search.vue (1)
560-583: Avoid overlapping polling timers on repeated Enter presses.Each Enter press starts a new interval/timeout pair. If users press Enter multiple times quickly, timers stack and keep resetting the debounced navigation. Consider reusing a single timer pair.
Proposed refactor
+let waitSearchResultInterval: ReturnType<typeof setInterval> | null = null +let waitSearchResultTimeout: ReturnType<typeof setTimeout> | null = null + +function clearSearchResultTimers() { + if (waitSearchResultInterval) clearInterval(waitSearchResultInterval) + if (waitSearchResultTimeout) clearTimeout(waitSearchResultTimeout) + waitSearchResultInterval = null + waitSearchResultTimeout = null +} + function handleResultsKeydown(e: KeyboardEvent) { // If the active element is an input and there are results, navigate to the first result if (e.key === 'Enter' && document.activeElement?.tagName === 'INPUT') { + clearSearchResultTimers() // After entering quickly and pressing Enter, find the latest packages const latestPackageName = findLatestPackageName() // Find successful . navigate to package page if (latestPackageName) return navigateToPackage(latestPackageName) // Waiting for the latest search results (maximum 1.5 seconds) - let waitSearchResultInterval: ReturnType<typeof setInterval> | null - function clearSearchResultInterval() { - if (waitSearchResultInterval) clearInterval(waitSearchResultInterval) - waitSearchResultInterval = null - } waitSearchResultInterval = setInterval(() => { const latestPackageName = findLatestPackageName() if (latestPackageName) { - clearSearchResultInterval() + clearSearchResultTimers() return navigateToPackage(latestPackageName) } }, 100) - setTimeout(() => { - clearSearchResultInterval() - }, 1500) + waitSearchResultTimeout = setTimeout(() => { + clearSearchResultTimers() + }, 1500) }
app/pages/search.vue
Outdated
| // Find latest package name | ||
| function findLatestPackageName() { | ||
| const packageName = displayResults.value?.[0]?.package.name | ||
| if (packageName === query.value) { | ||
| return packageName.split('/') | ||
| } |
There was a problem hiding this comment.
Normalise query comparison to avoid missing exact matches.
The comparison is case‑sensitive and doesn’t trim whitespace, so typing “React ” won’t navigate even if the top result is the exact package.
Proposed fix
function findLatestPackageName() {
- const packageName = displayResults.value?.[0]?.package.name
- if (packageName === query.value) {
+ const packageName = displayResults.value?.[0]?.package?.name
+ const q = query.value.trim().toLowerCase()
+ if (packageName && packageName.toLowerCase() === q) {
return packageName.split('/')
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Find latest package name | |
| function findLatestPackageName() { | |
| const packageName = displayResults.value?.[0]?.package.name | |
| if (packageName === query.value) { | |
| return packageName.split('/') | |
| } | |
| // Find latest package name | |
| function findLatestPackageName() { | |
| const packageName = displayResults.value?.[0]?.package?.name | |
| const q = query.value.trim().toLowerCase() | |
| if (packageName && packageName.toLowerCase() === q) { | |
| return packageName.split('/') | |
| } | |
| } |
feat #916