diff --git a/internal/action/tab.go b/internal/action/tab.go index 357eefbf..12803ebf 100644 --- a/internal/action/tab.go +++ b/internal/action/tab.go @@ -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 -- knotmirror 0.0.1 From 2a1790d15ab80746e838cfb466acb92028f2b03f Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Fri, 12 Apr 2024 02:21:03 +0200 Subject: [PATCH 2/4] Don't call onSetActive for an already active pane Currently onSetActive is called when the user clicks with the mouse on a pane even if this pane is already active. We should avoid calling it in this case. Implementation detail: like with tabs in the previous commit, we cannot check if the pane is already active just by checking the index passed to the Tab's SetActive() (since the index may not change while the pane itself changes), we need to check state of the pane itself. So we move the onSetActive invocation from the Tab's SetActive() to the BufPane's SetActive(). --- internal/action/bufpane.go | 10 +++++++++- internal/action/tab.go | 5 ----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 73574859..422debfc 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -679,6 +679,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 @@ -694,8 +698,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 diff --git a/internal/action/tab.go b/internal/action/tab.go index 12803ebf..19189e6e 100644 --- a/internal/action/tab.go +++ b/internal/action/tab.go @@ -327,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 -- knotmirror 0.0.1 From 186817d0c425ec68c05d1af5c3b9b21e0333bc05 Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Fri, 12 Apr 2024 02:30:56 +0200 Subject: [PATCH 3/4] onSetPane doc: s/panel/bufpane/ It is pane, not panel. Also, let's call it bufpane here, like we do in other callbacks' descriptions. --- runtime/help/plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index 746d2f41..e37a5db4 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -51,7 +51,7 @@ which micro defines: * `postinit()`: initialization function called after `init()`. -* `onSetActive(bufpane)`: runs when changing the currently active panel. +* `onSetActive(bufpane)`: runs when changing the currently active bufpane. * `onBufferOpen(buf)`: runs when a buffer is opened. The input contains the buffer object. -- knotmirror 0.0.1 From 4283881591d05963ed65a68f54261d88ad960b3d Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Fri, 12 Apr 2024 02:33:16 +0200 Subject: [PATCH 4/4] onSetActive doc: move it Cosmetic change: move onSetActive description to keep it together with other callbacks that are associated with bufpane, not with buffer. --- runtime/help/plugins.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index e37a5db4..948e7b72 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -51,14 +51,14 @@ which micro defines: * `postinit()`: initialization function called after `init()`. -* `onSetActive(bufpane)`: runs when changing the currently active bufpane. - * `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