16 type LeafNode struct {
22 func NewLeafNode(v *View, parent *SplitTree) *LeafNode {
30 type SplitTree struct {
45 func (l *LeafNode) VSplit(buf *Buffer) {
46 tab := tabs[l.parent.tabNum]
47 if l.parent.kind == VerticalSplit {
48 newView := NewView(buf)
49 newView.TabNum = l.parent.tabNum
50 newView.Num = len(tab.views)
51 l.parent.children = append(l.parent.children, NewLeafNode(newView, l.parent))
54 tab.views = append(tab.views, newView)
57 s.kind = VerticalSplit
59 newView := NewView(buf)
60 newView.TabNum = l.parent.tabNum
61 newView.Num = len(tab.views)
62 s.children = []Node{l, NewLeafNode(newView, s)}
63 l.parent.children[search(l.parent.children, l)] = s
67 tab.views = append(tab.views, newView)
71 func (l *LeafNode) HSplit(buf *Buffer) {
72 tab := tabs[l.parent.tabNum]
73 if l.parent.kind == HorizontalSplit {
74 newView := NewView(buf)
75 newView.TabNum = l.parent.tabNum
76 newView.Num = len(tab.views)
77 l.parent.children = append(l.parent.children, NewLeafNode(newView, l.parent))
80 tab.views = append(tab.views, newView)
83 s.kind = HorizontalSplit
85 newView := NewView(buf)
86 newView.TabNum = l.parent.tabNum
87 newView.Num = len(tab.views)
88 s.children = []Node{l, NewLeafNode(newView, s)}
89 l.parent.children[search(l.parent.children, l)] = s
93 tab.views = append(tab.views, newView)
97 func (l *LeafNode) Delete() {
98 i := search(l.parent.children, l)
100 copy(l.parent.children[i:], l.parent.children[i+1:])
101 l.parent.children[len(l.parent.children)-1] = nil
102 l.parent.children = l.parent.children[:len(l.parent.children)-1]
104 tab := tabs[l.parent.tabNum]
105 j := findView(tab.views, l.view)
106 copy(tab.views[j:], tab.views[j+1:])
107 tab.views[len(tab.views)-1] = nil // or the zero value of T
108 tab.views = tab.views[:len(tab.views)-1]
110 for i, v := range tab.views {
118 func (s *SplitTree) Cleanup() {
119 for i, node := range s.children {
120 if n, ok := node.(*SplitTree); ok {
121 if len(n.children) == 1 {
122 if child, ok := n.children[0].(*LeafNode); ok {
123 s.children[i] = child
133 func (s *SplitTree) ResizeSplits() {
134 for i, node := range s.children {
135 if n, ok := node.(*LeafNode); ok {
136 if s.kind == VerticalSplit {
137 n.view.width = s.width / len(s.children)
138 n.view.height = s.height
140 n.view.x = s.x + n.view.width*i
143 n.view.height = s.height / len(s.children)
144 n.view.width = s.width
146 n.view.y = s.y + n.view.height*i
149 // n.view.ToggleStatusLine()
150 _, screenH := screen.Size()
151 if settings["statusline"].(bool) || (n.view.y+n.view.height) != screenH-1 {
155 n.view.ToggleTabbar()
156 n.view.matches = Match(n.view)
157 } else if n, ok := node.(*SplitTree); ok {
158 if s.kind == VerticalSplit {
159 n.width = s.width / len(s.children)
162 n.x = s.x + n.width*i
165 n.height = s.height / len(s.children)
168 n.y = s.y + n.height*i
176 func (l *LeafNode) String() string {
177 return l.view.Buf.Name
180 func search(haystack []Node, needle Node) int {
181 for i, x := range haystack {
189 func findView(haystack []*View, needle *View) int {
190 for i, x := range haystack {
198 func (s *SplitTree) VSplit(buf *Buffer) {}
199 func (s *SplitTree) HSplit(buf *Buffer) {}
201 func (s *SplitTree) String() string {
203 for _, child := range s.children {
204 str += child.String() + ", "