Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,14 @@ func (h *BufPane) Tab() *Tab {
return h.tab
}

func (h *BufPane) ResizePane(size int) {
// ResizePane resizes the pane to a given size in the specified direction
func (h *BufPane) ResizePane(size int, right_or_bottom bool) bool {
n := h.tab.GetNode(h.splitID)
n.ResizeSplit(size)
h.tab.Resize()
r := n.ResizeSplit(size, right_or_bottom)
if r {
h.tab.Resize()
}
return r
}

// PluginCB calls all plugin callbacks with a certain name and displays an
Expand Down
2 changes: 1 addition & 1 deletion internal/action/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (t *Tab) HandleEvent(event tcell.Event) {
} else {
size = my - t.resizing.Y + 1
}
t.resizing.ResizeSplit(size)
t.resizing.ResizeSplit(size, true)
t.Resize()
return
}
Expand Down
58 changes: 42 additions & 16 deletions internal/views/splits.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (n *Node) SetPropScale(b bool) {
n.propScale = b
}

// Parent returns this node's parent
func (n *Node) Parent() *Node {
return n.parent
}

// Children returns this node's children
func (n *Node) Children() []*Node {
return n.children
Expand All @@ -140,15 +145,26 @@ func (n *Node) GetNode(id uint64) *Node {
return nil
}

func (n *Node) vResizeSplit(i int, size int) bool {
// vResizeSplit resizes a node vertically on the given side
func (n *Node) vResizeSplit(i int, size int, bottom bool) bool {
if i < 0 || i >= len(n.children) {
return false
}
var c1, c2 *Node
if i == len(n.children)-1 {
c1, c2 = n.children[i-1], n.children[i]
} else {
if bottom {
if i == len(n.children)-1 {
return false
}
c1, c2 = n.children[i], n.children[i+1]
} else {
if i == 0 {
return false
}
c1, c2 = n.children[i-1], n.children[i]
size = c1.H + c2.H - size
}
if size <= 0 || size >= n.H {
return false
}
toth := c1.H + c2.H
if size >= toth {
Expand All @@ -161,15 +177,27 @@ func (n *Node) vResizeSplit(i int, size int) bool {
n.alignSizes(n.W, n.H)
return true
}
func (n *Node) hResizeSplit(i int, size int) bool {

// hResizeSplit resizes a node horizontally on the given side
func (n *Node) hResizeSplit(i int, size int, right bool) bool {
if i < 0 || i >= len(n.children) {
return false
}
var c1, c2 *Node
if i == len(n.children)-1 {
c1, c2 = n.children[i-1], n.children[i]
} else {
if right {
if i == len(n.children)-1 {
return false
}
c1, c2 = n.children[i], n.children[i+1]
} else {
if i == 0 {
return false
}
c1, c2 = n.children[i-1], n.children[i]
size = c1.W + c2.W - size
}
if size <= 0 || size >= n.W {
return false
}
totw := c1.W + c2.W
if size >= totw {
Expand All @@ -183,12 +211,8 @@ func (n *Node) hResizeSplit(i int, size int) bool {
return true
}

// ResizeSplit resizes a certain split to a given size
func (n *Node) ResizeSplit(size int) bool {
// TODO: `size < 0` does not work for some reason
if size <= 0 {
return false
}
// ResizeSplit resizes a node to a given size in the specified direction
func (n *Node) ResizeSplit(size int, right_or_bottom bool) bool {
if len(n.parent.children) <= 1 {
// cannot resize a lone node
return false
Expand All @@ -200,9 +224,11 @@ func (n *Node) ResizeSplit(size int) bool {
}
}
if n.parent.Kind == STVert {
return n.parent.vResizeSplit(ind, size)
return n.parent.vResizeSplit(ind, size, right_or_bottom)
} else if n.parent.Kind == STHoriz {
return n.parent.hResizeSplit(ind, size, right_or_bottom)
}
return n.parent.hResizeSplit(ind, size)
return false
}

// Resize sets this node's size and resizes all children accordingly
Expand Down
2 changes: 1 addition & 1 deletion internal/views/splits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func TestHSplit(t *testing.T) {
root := NewRoot(0, 0, 80, 80)
n1 := root.VSplit(true)
root.GetNode(n1).VSplit(true)
root.GetNode(root.id).ResizeSplit(7)
root.GetNode(root.id).ResizeSplit(7, true)
root.Resize(120, 120)

fmt.Println(root.String())
Expand Down
Loading