mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
Merge pull request #308 from kurnevsky/fuzzy-sort
Make fuzzy sort show shorter strings first
This commit is contained in:
commit
41e8708eb5
@ -92,6 +92,10 @@
|
|||||||
Add adwaitaTheme and adwaitaDarkTheme to match their respective
|
Add adwaitaTheme and adwaitaDarkTheme to match their respective
|
||||||
GTK themes.
|
GTK themes.
|
||||||
|
|
||||||
|
* `XMonad.Prompt.FuzzyMatch`
|
||||||
|
|
||||||
|
Make fuzzy sort show shorter strings first.
|
||||||
|
|
||||||
|
|
||||||
## 0.15
|
## 0.15
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import Data.Function
|
|||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
--
|
--
|
||||||
-- This module offers two aspects of fuzzy matching of completions offered by
|
-- This module offers two aspects of fuzzy matching of completions offered by
|
||||||
-- XMonad.Prompt.
|
-- XMonad.Prompt.
|
||||||
--
|
--
|
||||||
@ -57,7 +57,7 @@ import Data.List
|
|||||||
-- > myXPConfig = def { searchPredicate = fuzzyMatch
|
-- > myXPConfig = def { searchPredicate = fuzzyMatch
|
||||||
-- > , sorter = fuzzySort
|
-- > , sorter = fuzzySort
|
||||||
-- > }
|
-- > }
|
||||||
--
|
--
|
||||||
-- then add this to your keys definition:
|
-- then add this to your keys definition:
|
||||||
--
|
--
|
||||||
-- > , ((modm .|. shiftMask, xK_g), windowPrompt myXPConfig Goto allWindows)
|
-- > , ((modm .|. shiftMask, xK_g), windowPrompt myXPConfig Goto allWindows)
|
||||||
@ -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
|
-- measured first by the length of the substring containing the match and second
|
||||||
-- by the positions of the matching characters in the string.
|
-- by the positions of the matching characters in the string.
|
||||||
fuzzySort :: String -> [String] -> [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 :: String -> String -> ((Int, Int), String)
|
||||||
rankMatch q s = (minimum $ rankMatches q s, s)
|
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..]
|
findOccurrences s c = map snd $ filter ((toLower c ==) . toLower . fst) $ zip s [0..]
|
||||||
|
|
||||||
extendMatches :: [(Int, Int)] -> [Int] -> [(Int, Int)]
|
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' :: [(Int, Int)] -> [Int] -> [(Int, Int)]
|
||||||
extendMatches' [] _ = []
|
extendMatches' [] _ = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user