]> git.lizzy.rs Git - micro.git/commitdiff
Fix unsplit crash
authorZachary Yedidia <zyedidia@gmail.com>
Sun, 9 Feb 2020 02:06:13 +0000 (21:06 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Sun, 9 Feb 2020 02:06:13 +0000 (21:06 -0500)
Fixes #1488

internal/action/actions.go
internal/views/splits.go

index 3f0d6ee1a58a00bbf4e88d36bbe35d5d7faa52da..783bffad94464d9e22c1cda8f02ab92b87673d61 100644 (file)
@@ -1373,38 +1373,42 @@ func (h *BufPane) HSplitAction() bool {
 
 // Unsplit closes all splits in the current tab except the active one
 func (h *BufPane) Unsplit() bool {
-       n := MainTab().GetNode(h.splitID)
-       n.Unsplit()
+       tab := h.tab
+       n := tab.GetNode(h.splitID)
+       ok := n.Unsplit()
+       if ok {
+               tab.RemovePane(tab.GetPane(h.splitID))
+               tab.Resize()
+               tab.SetActive(len(tab.Panes) - 1)
 
-       MainTab().RemovePane(MainTab().GetPane(h.splitID))
-       MainTab().Resize()
-       MainTab().SetActive(len(MainTab().Panes) - 1)
-       return true
+               return true
+       }
+       return false
 }
 
 // NextSplit changes the view to the next split
 func (h *BufPane) NextSplit() bool {
-       a := MainTab().active
-       if a < len(MainTab().Panes)-1 {
+       a := h.tab.active
+       if a < len(h.tab.Panes)-1 {
                a++
        } else {
                a = 0
        }
 
-       MainTab().SetActive(a)
+       h.tab.SetActive(a)
 
        return true
 }
 
 // PreviousSplit changes the view to the previous split
 func (h *BufPane) PreviousSplit() bool {
-       a := MainTab().active
+       a := h.tab.active
        if a > 0 {
                a--
        } else {
-               a = len(MainTab().Panes) - 1
+               a = len(h.tab.Panes) - 1
        }
-       MainTab().SetActive(a)
+       h.tab.SetActive(a)
 
        return true
 }
index 55d9d751f975dba7711d0a221d77d6bd4855925a..1168ab5d6aa9149bf24e70c438353535e372da9b 100644 (file)
@@ -456,9 +456,9 @@ func (n *Node) unsplit(i int, h bool) {
 
 // Unsplit deletes this split and resizes everything
 // else accordingly
-func (n *Node) Unsplit() {
-       if !n.IsLeaf() {
-               return
+func (n *Node) Unsplit() bool {
+       if !n.IsLeaf() || n.parent == nil {
+               return false
        }
        ind := 0
        for i, c := range n.parent.children {
@@ -473,8 +473,9 @@ func (n *Node) Unsplit() {
        }
 
        if n.parent.IsLeaf() {
-               n.parent.Unsplit()
+               return n.parent.Unsplit()
        }
+       return true
 }
 
 // String returns the string form of the node and all children (used for debugging)