From c6dc5a4b1fd56ed4bce5d53f623e26d29793601b Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Fri, 12 Apr 2024 02:07:29 +0200 Subject: [PATCH] Call onSetActive when switching to another tab We should call the onSetActive callback not only when switching to another bufpane within the same tab but also when switching to another tab. Note on implementation details: - In SetActive() we need to check if the tab is not already active, to avoid calling onSetActive for an already active bufpane. - We cannot check that just by checking if the tab index passed to SetActive() is different from the current active tab index, since this index may remain the same even if the tab itself is different (in the case of removing a tab from the tablist). So we need to check the tab itself, not just the tab index. So we introduce the isActive field, to track the tab's active state in the Tab structure itself. --- internal/action/tab.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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