Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/pages/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,48 @@ function focusElement(el: HTMLElement) {
el.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
}

// Find latest package name
function findLatestPackageName() {
const packageName = displayResults.value?.[0]?.package.name
if (packageName === query.value) {
return packageName.split('/')
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
// 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('/')
}
}

}

// Navigate to package page
const navigateToPackage = debounce((packageName?: string[]) => {
router.push({
name: 'package',
params: { package: packageName },
})
}, 500)

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') {
// 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) {
Comment thread
danielroe marked this conversation as resolved.
Outdated
clearSearchResultInterval()
return navigateToPackage(latestPackageName)
}
}, 100)

setTimeout(() => {
clearSearchResultInterval()
}, 1500)
}

if (totalSelectableCount.value <= 0) return

const elements = getFocusableElements()
Expand Down
Loading