From 19a4350cb6064168fba3d1772836591d95d92156 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 9 Feb 2020 11:29:28 +0000 Subject: [PATCH] Respect folding when rendering nodes --- src/Forest/Client/Node.hs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Forest/Client/Node.hs b/src/Forest/Client/Node.hs index 5a587f0..ff0dfb4 100644 --- a/src/Forest/Client/Node.hs +++ b/src/Forest/Client/Node.hs @@ -6,7 +6,6 @@ module Forest.Client.Node ) where import Brick -import qualified Data.Map as Map import qualified Data.Set as Set import Forest.Client.NodeEditor @@ -23,6 +22,9 @@ data DrawState = DrawState isFocused :: DrawState -> Bool isFocused ds = (isLocalPath <$> dsFocused ds) == Just True +isFolded :: DrawState -> Bool +isFolded ds = not $ localPath `Set.member` dsUnfolded ds + narrowDrawState :: NodeId -> DrawState -> DrawState narrowDrawState nodeId ds = ds { dsUnfolded = narrowSet nodeId $ dsUnfolded ds @@ -36,15 +38,13 @@ nodeToWidget focused node = focusStyle = if focused then "focus" else "nofocus" in withDefAttr focusStyle $ withDefAttr expandStyle nodeWidget -subnodeToTree :: NodeId -> DrawState -> Node -> WidgetTree ResourceName -subnodeToTree nodeId ds node = +subnodeToTree :: DrawState -> NodeId -> Node -> WidgetTree ResourceName +subnodeToTree ds nodeId node = let newDs = narrowDrawState nodeId ds in nodeToTree newDs node -subnodesToTrees :: DrawState -> Map.Map NodeId Node -> [WidgetTree ResourceName] -subnodesToTrees ds nodes = - map (\(nodeId, node) -> subnodeToTree nodeId ds node) $ - Map.toAscList nodes +subnodesToTrees :: DrawState -> Node -> [WidgetTree ResourceName] +subnodesToTrees ds = mapChildren (subnodeToTree ds) nodeToTree :: DrawState -> Node -> WidgetTree ResourceName nodeToTree ds node = case dsEditor ds of @@ -55,5 +55,6 @@ nodeToTree ds node = case dsEditor ds of | otherwise -> WidgetTree (renderNodeEditor ed) subnodeWidgets where focused = isFocused ds + folded = isFolded ds nodeWidget = nodeToWidget focused node - subnodeWidgets = subnodesToTrees ds $ nodeChildren node + subnodeWidgets = if folded then [] else subnodesToTrees ds node