-
Notifications
You must be signed in to change notification settings - Fork 26
/
tab.go
55 lines (46 loc) · 922 Bytes
/
tab.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package view
import (
"github.com/derailed/tview"
"github.com/gdamore/tcell/v2"
)
type Tab struct {
*App
items []tview.Primitive
}
func NewTab(app *App) *Tab {
t := Tab{App: app, items: []tview.Primitive{}}
t.Add()
return &t
}
func (t *Tab) Add() {
t.items = append(t.items, t.App.profile())
t.items = append(t.items, t.App.region())
}
func (t *Tab) tabAction(event *tcell.EventKey) *tcell.EventKey {
if t.InCmdMode() {
return event
}
focusIdx := t.currentFocusIdx()
if event.Key() == tcell.KeyTAB {
if focusIdx + 1 == len(t.items) {
t.App.Application.SetFocus(t.Content.Pages.Current())
return event
}
focusIdx = focusIdx + 1
}
if focusIdx < 0 {
focusIdx = 0
}
t.App.Application.SetFocus(t.items[focusIdx])
return event
}
func (t *Tab) currentFocusIdx() int {
focusIdx := -1
for i, p := range t.items {
if p.HasFocus() {
focusIdx = i
break
}
}
return focusIdx
}