Skip to content

Commit

Permalink
make fuzzy scoring more robust against whitespaces (JuliaLang#39932)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Apr 3, 2021
1 parent 78b629f commit 8d1f052
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,10 @@ function matchinds(needle, haystack; acronym::Bool = false)
is = Int[]
lastc = '\0'
for (i, char) in enumerate(haystack)
while !isempty(chars) && isspace(first(chars))
popfirst!(chars) # skip spaces
end
isempty(chars) && break
while chars[1] == ' ' popfirst!(chars) end # skip spaces
if lowercase(char) == lowercase(chars[1]) &&
(!acronym || !isletter(lastc))
push!(is, i)
Expand Down
6 changes: 6 additions & 0 deletions stdlib/REPL/test/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ end
# https://github.com/JuliaLang/julia/issues/37757
@test REPL.insert_hlines(IOBuffer(), nothing) === nothing
end

@testset "fuzzy score" begin
# https://github.com/JunoLab/FuzzyCompletions.jl/issues/7
# shouldn't throw when there is a space in a middle of query
@test (REPL.matchinds("a ", "a file.txt"); true)
end

0 comments on commit 8d1f052

Please sign in to comment.