mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-03 11:41:06 +03:00
apply a function to selected element
This commit is contained in:
parent
764610f628
commit
7043fa56d9
@ -37,6 +37,7 @@ module Brick.Widgets.List
|
||||
, listSelectedElement
|
||||
, listClear
|
||||
, listReverse
|
||||
, listModify
|
||||
|
||||
-- * Attributes
|
||||
, listAttr
|
||||
@ -281,3 +282,13 @@ listReverse :: List n e -> List n e
|
||||
listReverse theList = theList & listElementsL %~ V.reverse & listSelectedL .~ newSel
|
||||
where n = V.length (listElements theList)
|
||||
newSel = (-) <$> pure (n-1) <*> listSelected theList
|
||||
|
||||
|
||||
|
||||
-- | Apply a function to the selected element. If no element is selected the
|
||||
-- list is not modified.
|
||||
listModify :: (e -> e) -> List n e -> List n e
|
||||
listModify f l = case listSelectedElement l of
|
||||
Nothing -> l
|
||||
Just (n,e) -> let vs = V.update (l^.listElementsL) (return (n, f e))
|
||||
in listReplace vs (Just n) l
|
Loading…
Reference in New Issue
Block a user