summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKierán Meinhardt <kieran.meinhardt@gmail.com>2020-09-22 23:37:06 +0200
committerKierán Meinhardt <kieran.meinhardt@gmail.com>2020-09-22 23:37:06 +0200
commit121d703bcd3ecbaba031499070907251b5eae1a9 (patch)
tree40ad272443c65ac68c0e3ddd38d23c543ef6c78c
parentc7fc18648a6fe295d14284cb491b9ea2d1a28cac (diff)
Action: add openFold and closeFold
-rw-r--r--Action.hs24
1 files changed, 16 insertions, 8 deletions
diff --git a/Action.hs b/Action.hs
index 08c30a4..7ca023d 100644
--- a/Action.hs
+++ b/Action.hs
@@ -134,18 +134,26 @@ moveCursorDownToNextUnread =
moveCursorToUnread findNext botOverrun moveTreeUp
-toggleFold :: State -> IO State
-toggleFold q@State{..} =
- getNewSubForest >>= return . \case
+openFold :: State -> IO State
+openFold q@State{..} =
+ handle <$> loadSubForest (Z.label cursor)
+ where
+ handle = \case
Left err ->
q { flashMessage = SGR [31] $ Plain err }
Right sf ->
q { cursor = Z.modifyTree (setSubForest sf) cursor }
- where
- getNewSubForest =
- if hasUnloadedSubForest (Z.tree cursor)
- then loadSubForest (Z.label cursor)
- else return $ Right $ unloadSubForest (Z.tree cursor)
+
+closeFold :: State -> IO State
+closeFold q@State{..} =
+ let sf = unloadSubForest (Z.tree cursor)
+ in return q { cursor = Z.modifyTree (setSubForest sf) cursor }
+
+toggleFold :: State -> IO State
+toggleFold q@State{..} =
+ if hasUnloadedSubForest (Z.tree cursor)
+ then openFold q
+ else closeFold q
toggleTagAtCursor :: Tag -> State -> IO State