@@ -859,6 +859,44 @@ Example:
859859 " Move right to the next pane."
860860 (layout/set (layout/move-right (layout/get ))))
861861
862+ (defn-
863+ resize-pane
864+ ``` Find the nearest parent split of the attached pane and adjust its size.
865+ direction should be 1 (grow) or -1 (shrink).```
866+ [direction ]
867+ (def layout (layout/get ))
868+ (def path (layout/attach-path layout ))
869+ (if (nil? path ) (break ))
870+ (def split-path (layout/find-last layout path |(layout/type? :split $ )))
871+ (if (nil? split-path ) (break ))
872+ (def split-node (layout/path layout split-path ))
873+
874+ # Determine which side the attached pane is on
875+ (def side (get path (length split-path )))
876+
877+ # If on side B, flip direction since percent/cells refers to side A
878+ (def sign (if (= side :b ) (- direction ) direction ))
879+
880+ (def new-split
881+ (if (not (nil? (split-node :cells )))
882+ (assoc split-node :cells
883+ (max 1 (+ (split-node :cells ) (* sign 3 ))))
884+ (let [current (or (split-node :percent ) 50 )]
885+ (assoc split-node :percent
886+ (max 1 (min 99 (+ current (* sign 10 ))))))))
887+
888+ (layout/set (layout/assoc layout split-path new-split )))
889+
890+ (key/action
891+ action/grow-split
892+ " Grow the current pane within its split."
893+ (resize-pane 1 ))
894+
895+ (key/action
896+ action/shrink-split
897+ " Shrink the current pane within its split."
898+ (resize-pane -1 ))
899+
862900(key/action
863901 action/add-node
864902 " Add a node to the layout."
0 commit comments