Merge pull request #3245 from dmaluka/onsetactive-fix

Fix issues with `onSetActive` callback
This commit is contained in:
Dmytro Maluka 2024-04-23 21:28:03 +02:00 committed by GitHub
commit 18f3e1bf89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 8 deletions

View File

@ -689,6 +689,10 @@ func (h *BufPane) Close() {
// SetActive marks this pane as active.
func (h *BufPane) SetActive(b bool) {
if h.IsActive() == b {
return
}
h.BWindow.SetActive(b)
if b {
// Display any gutter messages for this line
@ -704,8 +708,12 @@ func (h *BufPane) SetActive(b bool) {
if none && InfoBar.HasGutter {
InfoBar.ClearGutter()
}
}
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, h))
if err != nil {
screen.TermMessage(err)
}
}
}
// BufKeyActions contains the list of all possible key actions the bufhandler could execute

View File

@ -147,6 +147,25 @@ func (t *TabList) Display() {
}
}
func (t *TabList) SetActive(a int) {
t.TabWindow.SetActive(a)
for i, p := range t.List {
if i == a {
if !p.isActive {
p.isActive = true
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, p.CurPane()))
if err != nil {
screen.TermMessage(err)
}
}
} else {
p.isActive = false
}
}
}
// Tabs is the global tab list
var Tabs *TabList
@ -192,6 +211,9 @@ func MainTab() *Tab {
type Tab struct {
*views.Node
*display.UIWindow
isActive bool
Panes []Pane
active int
@ -305,11 +327,6 @@ func (t *Tab) SetActive(i int) {
p.SetActive(false)
}
}
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, MainTab().CurPane()))
if err != nil {
screen.TermMessage(err)
}
}
// GetPane returns the pane with the given split index

View File

@ -51,14 +51,14 @@ which micro defines:
* `postinit()`: initialization function called after `init()`.
* `onSetActive(bufpane)`: runs when changing the currently active panel.
* `onBufferOpen(buf)`: runs when a buffer is opened. The input contains
the buffer object.
* `onBufPaneOpen(bufpane)`: runs when a bufpane is opened. The input
contains the bufpane object.
* `onSetActive(bufpane)`: runs when changing the currently active bufpane.
* `onAction(bufpane)`: runs when `Action` is triggered by the user, where
`Action` is a bindable action (see `> help keybindings`). A bufpane
is passed as input and the function should return a boolean defining