mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 23:05:40 -04:00
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.
This commit is contained in:
parent
2e44db1ee9
commit
5f83661fee
@ -663,9 +663,13 @@ func (h *BufPane) DoRuneInsert(r rune) {
|
||||
func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
|
||||
e := NewBufPaneFromBuf(buf, h.tab)
|
||||
e.splitID = MainTab().GetNode(h.splitID).VSplit(right)
|
||||
MainTab().Panes = append(MainTab().Panes, e)
|
||||
currentPaneIdx := MainTab().GetPane(h.splitID)
|
||||
if right {
|
||||
currentPaneIdx++
|
||||
}
|
||||
MainTab().AddPane(e, currentPaneIdx)
|
||||
MainTab().Resize()
|
||||
MainTab().SetActive(len(MainTab().Panes) - 1)
|
||||
MainTab().SetActive(currentPaneIdx)
|
||||
return e
|
||||
}
|
||||
|
||||
@ -673,9 +677,13 @@ func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
|
||||
func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
|
||||
e := NewBufPaneFromBuf(buf, h.tab)
|
||||
e.splitID = MainTab().GetNode(h.splitID).HSplit(bottom)
|
||||
MainTab().Panes = append(MainTab().Panes, e)
|
||||
currentPaneIdx := MainTab().GetPane(h.splitID)
|
||||
if bottom {
|
||||
currentPaneIdx++
|
||||
}
|
||||
MainTab().AddPane(e, currentPaneIdx)
|
||||
MainTab().Resize()
|
||||
MainTab().SetActive(len(MainTab().Panes) - 1)
|
||||
MainTab().SetActive(currentPaneIdx)
|
||||
return e
|
||||
}
|
||||
|
||||
|
@ -349,6 +349,16 @@ func (t *Tab) SetActive(i int) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddPane adds a pane at a given index
|
||||
func (t *Tab) AddPane(pane Pane, i int) {
|
||||
if len(t.Panes) == i {
|
||||
t.Panes = append(t.Panes, pane)
|
||||
return
|
||||
}
|
||||
t.Panes = append(t.Panes[:i+1], t.Panes[i:]...)
|
||||
t.Panes[i] = pane
|
||||
}
|
||||
|
||||
// GetPane returns the pane with the given split index
|
||||
func (t *Tab) GetPane(splitid uint64) int {
|
||||
for i, p := range t.Panes {
|
||||
|
Loading…
Reference in New Issue
Block a user