Skip to content

Commit

Permalink
Check for a full submatch first
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Aug 6, 2024
1 parent 476f91f commit 9490b6e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package/src/extensions/autocomplete/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ const fuzzyFilter: CompletionFilter = (query: string, option: string) => {
const queryLc = query.toLowerCase()
const optionLc = option.toLowerCase()
const matched: number[] = []
const fullMatch = optionLc.indexOf(queryLc)

let score = 0
let i = 0
let prevPos = 0
let j = 0
for (; i < queryLen; i++) {
const char = queryLc[i]
const pos = optionLc.indexOf(char, prevPos)
const pos = fullMatch > -1 ? i + fullMatch : optionLc.indexOf(char, prevPos)
const hasSkipped = pos > prevPos

if (pos < 0) return
Expand Down

0 comments on commit 9490b6e

Please sign in to comment.