Rethink selection lists as intmaps

This commit is contained in:
2023-01-15 23:17:47 +00:00
parent 17734738f6
commit 048135c370
17 changed files with 245 additions and 93 deletions
+23 -14
View File
@@ -16,25 +16,34 @@ getAvailableListLines ldps cfig = floor ((dToBot - vgap) / itmHeight)
dToBot = cfig ^. windowY - (ldps ^. ldpPosY + dFromScreenBot)
dFromScreenBot = 5 -- fromMaybe 0 $ sl ^? slSizeRestriction . ssrType . ssrFromScreenBottom
defaultSelectionList :: SelectionList a
defaultSelectionList = SelectionList
{_slItems = []
, _slSelPos = Nothing
, _slLength = 0
, _slRegex = ""
, _slRegexInput = False
}
getShownItems :: SelectionList a -> [SelectionItem a]
getShownItems sl = case sl ^. slRegex of
"" | not (sl ^. slRegexInput) -> _slItems sl
str -> SelectionFilter
getShownItems sl = case sl ^. slRegexList of
[] -> sl ^. slItems
xs -> map fst xs
makeRegexList :: SelectionList a -> [(SelectionItem a, Maybe Int)]
makeRegexList sl = case sl ^. slRegex of
"" | not (sl ^. slRegexInput) -> []
str -> (SelectionInfo
{ _siPictures = ["FILTER: "++str]
, _siHeight = 1
, _siIsSelectable = False
, _siWidth = length $ "FILTER: "++str
, _siColor = white
, _siOffX = 0
}: filter (doregex str) (_slItems sl)
}, Nothing) : filter (doregex str) (zip (_slItems sl) $ fmap Just [0..])
where
doregex str = regexList str . _siPictures
doregex str = regexList str . _siPictures . fst
setShownItems :: SelectionList a -> SelectionList a
setShownItems sl = sl & slRegexList .~ makeRegexList sl
moveSelectionListSelection :: Int -> SelectionList a -> SelectionList a
moveSelectionListSelection yi sl = sl & slSelPos %~ f
where
f x | maxsel == 0 = Nothing
| x == Nothing = Just 0
| otherwise = fmap ((`mod` maxsel) . subtract yi) x
maxsel = case _slRegex sl of
"" -> length (_slItems sl)
_ -> length (_slRegexList sl)