From 14ba338de914145cee55093ba8c866bc411c7f28 Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Wed, 7 Apr 2021 23:03:20 -0500 Subject: [PATCH] PanelContainer: bug fix on destroying a panel This commit fixes a bug where destroying a Panel with a parent of kind PanelKindSplit... causes the selected to become that split panel, instead of a child. Now, it chooses the leftmost child of that parent panel. --- ui/panelcontainer.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/panelcontainer.go b/ui/panelcontainer.go index 981fcfb..e0716e6 100755 --- a/ui/panelcontainer.go +++ b/ui/panelcontainer.go @@ -76,15 +76,24 @@ func (c *PanelContainer) DeleteSelected() Component { } if (*p).Left != nil { + // Parent becomes the Left panel panel := (*p).Left.(*Panel) (*p).Left = (*panel).Left (*p).Right = (*panel).Right (*p).Kind = (*panel).Kind + (*p).SplitAt = (*panel).SplitAt } else { (*p).Kind = PanelKindEmpty } - c.changeSelected(&p) + // Decide what Panel to select next + if !(*p).IsLeaf() { // If the new panel was a split panel... + // Select the leftmost child of it + (*p).EachLeaf(false, func(l *Panel) bool { c.changeSelected(&l); return true }) + } else { + c.changeSelected(&p) + } + (*p).UpdateSplits() } else if c.floatingMode { // Deleting a floating Panel without a parent c.floating[0] = nil