Merge pull request #308 from kurnevsky/fuzzy-sort

Make fuzzy sort show shorter strings first
This commit is contained in:
Brent Yorgey 2019-08-08 21:45:23 -05:00 committed by GitHub
commit 41e8708eb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -92,6 +92,10 @@
Add adwaitaTheme and adwaitaDarkTheme to match their respective
GTK themes.
* `XMonad.Prompt.FuzzyMatch`
Make fuzzy sort show shorter strings first.
## 0.15

View File

@ -77,7 +77,7 @@ fuzzyMatch xxs@(x:xs) (y:ys) | toLower x == toLower y = fuzzyMatch xs ys
-- measured first by the length of the substring containing the match and second
-- by the positions of the matching characters in the string.
fuzzySort :: String -> [String] -> [String]
fuzzySort q = map snd . sortBy (compare `on` fst) . map (rankMatch q)
fuzzySort q = map snd . sort . map (rankMatch q)
rankMatch :: String -> String -> ((Int, Int), String)
rankMatch q s = (minimum $ rankMatches q s, s)
@ -95,7 +95,7 @@ findOccurrences :: String -> Char -> [Int]
findOccurrences s c = map snd $ filter ((toLower c ==) . toLower . fst) $ zip s [0..]
extendMatches :: [(Int, Int)] -> [Int] -> [(Int, Int)]
extendMatches spans xs = map last $ groupBy ((==) `on` snd) $ extendMatches' spans xs
extendMatches spans = map last . groupBy ((==) `on` snd) . extendMatches' spans
extendMatches' :: [(Int, Int)] -> [Int] -> [(Int, Int)]
extendMatches' [] _ = []