Skip to content

Commit

Permalink
add modifyFocus', returning an additional value
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Oct 7, 2023
1 parent 96875b1 commit 0beacf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/menu/lib/Ribosome/Menu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import Ribosome.Menu.ItemLens (
import Ribosome.Menu.Items (
deleteSelected,
modifyFocus,
modifyFocus',
traverseSelection_,
updateEntry,
withFocus,
Expand Down
21 changes: 16 additions & 5 deletions packages/menu/lib/Ribosome/Menu/Items.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,25 @@ updateEntry index newEntry = do
entries %= overEntry index (const newEntry)
items . ix (fromIntegral newEntry.index) .= newEntry.item

modifyFocus' ::
s a r .
MenuState s =>
Member (Menu s) r =>
(Entry (Item s) -> (Entry (Item s), a)) ->
Sem r (Maybe a)
modifyFocus' f =
menuState do
CursorIndex curs <- use #cursor
use focusEntry >>= traverse \ e -> do
let (new, result) = f e
updateEntry (fromIntegral curs) new
histories .= mempty
pure result

modifyFocus ::
MenuState s =>
Member (Menu s) r =>
(Entry (Item s) -> Entry (Item s)) ->
Sem r ()
modifyFocus f =
menuState do
CursorIndex curs <- use #cursor
use focusEntry >>= traverse_ \ e -> do
updateEntry (fromIntegral curs) (f e)
histories .= mempty
void $ modifyFocus' \ e -> (f e, ())

0 comments on commit 0beacf8

Please sign in to comment.