Skip to content

Commit ae66a29

Browse files
committed
feat: (action/shrink-split) and (action/grow-split)
1 parent 2892123 commit ae66a29

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pkg/cy/boot/binds.janet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
[prefix "L"] action/move-right
3939
[prefix "K"] action/move-up
4040
[prefix "J"] action/move-down
41+
[prefix "+"] action/grow-split
42+
[prefix "_"] action/shrink-split
4143
[prefix "t"] action/new-tab
4244
[prefix "tab"] action/next-tab
4345
[prefix "shift+tab"] action/prev-tab

pkg/cy/boot/layout.janet

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)