Skip to content

Commit 18f3e1b

Browse files
authored
Merge pull request zyedidia#3245 from dmaluka/onsetactive-fix
Fix issues with `onSetActive` callback
2 parents e48575f + 4283881 commit 18f3e1b

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

internal/action/bufpane.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ func (h *BufPane) Close() {
689689

690690
// SetActive marks this pane as active.
691691
func (h *BufPane) SetActive(b bool) {
692+
if h.IsActive() == b {
693+
return
694+
}
695+
692696
h.BWindow.SetActive(b)
693697
if b {
694698
// Display any gutter messages for this line
@@ -704,8 +708,12 @@ func (h *BufPane) SetActive(b bool) {
704708
if none && InfoBar.HasGutter {
705709
InfoBar.ClearGutter()
706710
}
707-
}
708711

712+
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, h))
713+
if err != nil {
714+
screen.TermMessage(err)
715+
}
716+
}
709717
}
710718

711719
// BufKeyActions contains the list of all possible key actions the bufhandler could execute

internal/action/tab.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,25 @@ func (t *TabList) Display() {
147147
}
148148
}
149149

150+
func (t *TabList) SetActive(a int) {
151+
t.TabWindow.SetActive(a)
152+
153+
for i, p := range t.List {
154+
if i == a {
155+
if !p.isActive {
156+
p.isActive = true
157+
158+
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, p.CurPane()))
159+
if err != nil {
160+
screen.TermMessage(err)
161+
}
162+
}
163+
} else {
164+
p.isActive = false
165+
}
166+
}
167+
}
168+
150169
// Tabs is the global tab list
151170
var Tabs *TabList
152171

@@ -192,6 +211,9 @@ func MainTab() *Tab {
192211
type Tab struct {
193212
*views.Node
194213
*display.UIWindow
214+
215+
isActive bool
216+
195217
Panes []Pane
196218
active int
197219

@@ -305,11 +327,6 @@ func (t *Tab) SetActive(i int) {
305327
p.SetActive(false)
306328
}
307329
}
308-
309-
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, MainTab().CurPane()))
310-
if err != nil {
311-
screen.TermMessage(err)
312-
}
313330
}
314331

315332
// GetPane returns the pane with the given split index

runtime/help/plugins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ which micro defines:
5151

5252
* `postinit()`: initialization function called after `init()`.
5353

54-
* `onSetActive(bufpane)`: runs when changing the currently active panel.
55-
5654
* `onBufferOpen(buf)`: runs when a buffer is opened. The input contains
5755
the buffer object.
5856

5957
* `onBufPaneOpen(bufpane)`: runs when a bufpane is opened. The input
6058
contains the bufpane object.
6159

60+
* `onSetActive(bufpane)`: runs when changing the currently active bufpane.
61+
6262
* `onAction(bufpane)`: runs when `Action` is triggered by the user, where
6363
`Action` is a bindable action (see `> help keybindings`). A bufpane
6464
is passed as input and the function should return a boolean defining

0 commit comments

Comments
 (0)