Skip to content

Commit 5f83661

Browse files
committed
Fixes a bug where new BufPanes are not being inserted into the right array index.
When adding a new `BufPane` it is always being inserted last into `MainTab().Panes`. This leads to a confusion when using the actions `PreviousSplit`, `NextSplit` as the previous/next split may not be the expected one. How to reproduce: - Launch micro and insert char "1" - Open a new vsplit via the command `vsplit` and insert "2" - Switch back to the left split (1) by using `PreviousSplit` - Again open a new vsplit via command: `vsplit` and type char "3" - Now switch between the 3 splits using `PreviousSplit`, `NextSplit` Switching from most left split to the most right, the expected order would be 1, 3, 2 but actually is 1, 2, 3.
1 parent 2e44db1 commit 5f83661

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

internal/action/bufpane.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,19 +663,27 @@ func (h *BufPane) DoRuneInsert(r rune) {
663663
func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
664664
e := NewBufPaneFromBuf(buf, h.tab)
665665
e.splitID = MainTab().GetNode(h.splitID).VSplit(right)
666-
MainTab().Panes = append(MainTab().Panes, e)
666+
currentPaneIdx := MainTab().GetPane(h.splitID)
667+
if right {
668+
currentPaneIdx++
669+
}
670+
MainTab().AddPane(e, currentPaneIdx)
667671
MainTab().Resize()
668-
MainTab().SetActive(len(MainTab().Panes) - 1)
672+
MainTab().SetActive(currentPaneIdx)
669673
return e
670674
}
671675

672676
// HSplitIndex opens the given buffer in a horizontal split on the given side.
673677
func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
674678
e := NewBufPaneFromBuf(buf, h.tab)
675679
e.splitID = MainTab().GetNode(h.splitID).HSplit(bottom)
676-
MainTab().Panes = append(MainTab().Panes, e)
680+
currentPaneIdx := MainTab().GetPane(h.splitID)
681+
if bottom {
682+
currentPaneIdx++
683+
}
684+
MainTab().AddPane(e, currentPaneIdx)
677685
MainTab().Resize()
678-
MainTab().SetActive(len(MainTab().Panes) - 1)
686+
MainTab().SetActive(currentPaneIdx)
679687
return e
680688
}
681689

internal/action/tab.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ func (t *Tab) SetActive(i int) {
349349
}
350350
}
351351

352+
// AddPane adds a pane at a given index
353+
func (t *Tab) AddPane(pane Pane, i int) {
354+
if len(t.Panes) == i {
355+
t.Panes = append(t.Panes, pane)
356+
return
357+
}
358+
t.Panes = append(t.Panes[:i+1], t.Panes[i:]...)
359+
t.Panes[i] = pane
360+
}
361+
352362
// GetPane returns the pane with the given split index
353363
func (t *Tab) GetPane(splitid uint64) int {
354364
for i, p := range t.Panes {

0 commit comments

Comments
 (0)