Implement unsplitting

This commit is contained in:
Zachary Yedidia
2019-01-09 16:55:00 -05:00
parent 4412b44b47
commit f2cb7d2fc1
3 changed files with 271 additions and 156 deletions

View File

@@ -987,16 +987,22 @@ func (h *BufHandler) Escape() bool {
// Quit this will close the current tab or view that is open
func (h *BufHandler) Quit() bool {
quit := func() {
if len(MainTab.Panes) > 1 {
h.Unsplit()
} else {
screen.Screen.Fini()
os.Exit(0)
}
}
if h.Buf.Modified() {
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
if !canceled && !yes {
screen.Screen.Fini()
os.Exit(0)
quit()
}
})
} else {
screen.Screen.Fini()
os.Exit(0)
quit()
}
return false
}
@@ -1033,6 +1039,12 @@ func (h *BufHandler) HSplitBinding() bool {
// Unsplit closes all splits in the current tab except the active one
func (h *BufHandler) Unsplit() bool {
n := MainTab.GetNode(h.splitID)
n.Unsplit()
MainTab.RemovePane(MainTab.GetPane(h.splitID))
MainTab.Resize()
MainTab.SetActive(len(MainTab.Panes) - 1)
return false
}

View File

@@ -56,13 +56,28 @@ func (t *TabPane) SetActive(i int) {
}
}
func (t *TabPane) GetPane(splitid uint64) int {
for i, p := range t.Panes {
if p.splitID == splitid {
return i
}
}
return 0
}
func (t *TabPane) RemovePane(i int) {
copy(t.Panes[i:], t.Panes[i+1:])
t.Panes[len(t.Panes)-1] = nil // or the zero value of T
t.Panes = t.Panes[:len(t.Panes)-1]
}
func (t *TabPane) Resize() {
for _, p := range t.Panes {
v := t.GetNode(p.splitID).GetView()
n := t.GetNode(p.splitID)
pv := p.GetView()
pv.X, pv.Y = v.X, v.Y
pv.X, pv.Y = n.X, n.Y
p.SetView(pv)
p.Resize(v.W, v.H)
p.Resize(n.W, n.H)
}
}