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.
This commit is contained in:
Dmytro Maluka
2024-04-12 02:07:29 +02:00
parent 426aa9bb8b
commit c6dc5a4b1f

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