From 2a1790d15ab80746e838cfb466acb92028f2b03f Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Fri, 12 Apr 2024 02:21:03 +0200 Subject: [PATCH] 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