Skip to content

Commit 042f5eb

Browse files
committed
call onSetActive whenever a bufpane becomes active
1 parent 2898f15 commit 042f5eb

File tree

6 files changed

+19
-25
lines changed

6 files changed

+19
-25
lines changed

cmd/micro/micro_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func startup(args []string) (tcell.SimulationScreen, error) {
8383
return nil, errors.New("No buffers opened")
8484
}
8585

86-
action.InitTabs(b)
8786
action.InitGlobals()
87+
action.InitTabs(b)
8888

8989
err = config.RunPluginFn("init")
9090
if err != nil {

internal/action/actions.go

+3
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,9 @@ func (h *BufPane) ForceQuit() bool {
18991899
h.Unsplit()
19001900
} else if len(Tabs.List) > 1 {
19011901
Tabs.RemoveTab(h.splitID)
1902+
if e := MainTab().CurPane(); e != nil { // e == nil for 'raw' tab
1903+
e.SetActive(true)
1904+
}
19021905
} else {
19031906
screen.Screen.Fini()
19041907
InfoBar.Close()

internal/action/bufpane.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
666666
}
667667
MainTab().AddPane(e, currentPaneIdx)
668668
MainTab().Resize()
669-
MainTab().SetActive(currentPaneIdx)
670669
return e
671670
}
672671

@@ -680,18 +679,23 @@ func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
680679
}
681680
MainTab().AddPane(e, currentPaneIdx)
682681
MainTab().Resize()
683-
MainTab().SetActive(currentPaneIdx)
684682
return e
685683
}
686684

687685
// VSplitBuf opens the given buffer in a new vertical split.
688686
func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane {
689-
return h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool))
687+
e := h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool))
688+
MainTab().SetActive(MainTab().GetPane(e.ID()))
689+
e.SetActive(true)
690+
return e
690691
}
691692

692693
// HSplitBuf opens the given buffer in a new horizontal split.
693694
func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane {
694-
return h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool))
695+
e := h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool))
696+
MainTab().SetActive(MainTab().GetPane(e.ID()))
697+
e.SetActive(true)
698+
return e
695699
}
696700

697701
// Close this pane.

internal/action/tab.go

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package action
22

33
import (
4-
luar "layeh.com/gopher-luar"
5-
64
"github.com/zyedidia/micro/v2/internal/buffer"
75
"github.com/zyedidia/micro/v2/internal/config"
86
"github.com/zyedidia/micro/v2/internal/display"
9-
ulua "github.com/zyedidia/micro/v2/internal/lua"
107
"github.com/zyedidia/micro/v2/internal/screen"
118
"github.com/zyedidia/micro/v2/internal/views"
129
"github.com/zyedidia/tcell/v2"
@@ -153,17 +150,9 @@ func (t *TabList) SetActive(a int) {
153150
t.TabWindow.SetActive(a)
154151

155152
for i, p := range t.List {
156-
if i == a {
157-
if !p.isActive {
158-
p.isActive = true
159-
160-
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, p.CurPane()))
161-
if err != nil {
162-
screen.TermMessage(err)
163-
}
164-
}
165-
} else {
166-
p.isActive = false
153+
p.isActive = i == a
154+
if h := p.CurPane(); h != nil { // h == nil for 'raw' tab
155+
h.SetActive(i == a)
167156
}
168157
}
169158
}
@@ -210,12 +199,13 @@ func InitTabs(bufs []*buffer.Buffer) {
210199
Tabs = NewTabList(bufs[:1])
211200
for _, b := range bufs[1:] {
212201
if multiopen == "vsplit" {
213-
MainTab().CurPane().VSplitBuf(b)
202+
MainTab().CurPane().VSplitIndex(b, true)
214203
} else { // default hsplit
215-
MainTab().CurPane().HSplitBuf(b)
204+
MainTab().CurPane().HSplitIndex(b, true)
216205
}
217206
}
218207
}
208+
MainTab().CurPane().SetActive(true)
219209

220210
screen.RestartCallback = Tabs.ResetMouse
221211
}

internal/display/bufwindow.go

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
3636
w.View = new(View)
3737
w.X, w.Y, w.Width, w.Height = x, y, width, height
3838
w.SetBuffer(buf)
39-
w.active = true
4039

4140
w.sline = NewStatusLine(w)
4241

runtime/help/plugins.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ that micro defines:
5757

5858
* `deinit()`: cleanup function called when your plugin is unloaded or reloaded.
5959

60-
* `onSetActive(bufpane)`: runs when changing the currently active panel.
61-
6260
* `onBufferOpen(buf)`: runs when a buffer is opened. The input contains
6361
the buffer object.
6462

6563
* `onBufPaneOpen(bufpane)`: runs when a bufpane is opened. The input
6664
contains the bufpane object.
6765

68-
* `onSetActive(bufpane)`: runs when changing the currently active bufpane.
66+
* `onSetActive(bufpane)`: runs when a bufpane becomes active.
6967

7068
* `onAction(bufpane)`: runs when `Action` is triggered by the user, where
7169
`Action` is a bindable action (see `> help keybindings`). A bufpane

0 commit comments

Comments
 (0)