Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong score calculation with leading/trailing white space on search string #347

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
4 changes: 3 additions & 1 deletion cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded

function score(value: string, keywords?: string[]) {
const filter = propsRef.current?.filter ?? defaultFilter
return value ? filter(value, state.current.search, keywords) : 0
const search = state.current.search ?? ''
const sanitizedSearch = search.replace(/\s+/g, ' ').trim()
return value ? filter(value, sanitizedSearch, keywords) : 0
}

/** Sorts items by score, and groups by highest item score. */
Expand Down