curTab--
}
if curTab == 0 {
- tab := tabs[curTab]
- tab.views[tab.curView].Resize(screen.Size())
+ CurView().Resize(screen.Size())
+ CurView().matches = Match(CurView())
}
}
} else {
tab.SetNum(len(tabs))
tabs = append(tabs, tab)
curTab++
+ if len(tabs) == 2 {
+ for _, t := range tabs {
+ for _, v := range t.views {
+ v.Resize(screen.Size())
+ }
+ }
+ }
return true
}
if curTab > 0 {
curTab--
}
- return true
+ return false
}
func (v *View) NextTab() bool {
if curTab < len(tabs)-1 {
curTab++
}
- return true
+ return false
}
// None is no action
// Wait for the user's action
event := screen.PollEvent()
+ if TabbarHandleMouseEvent(event) {
+ continue
+ }
if searching {
// Since searching is done in real time, we need to redraw every time
package main
+import (
+ "sort"
+
+ "github.com/zyedidia/tcell"
+)
+
type Tab struct {
// This contains all the views in this tab
// There is generally only one view per tab, but you can have
return curTab.views[curTab.curView]
}
-func DisplayTabs() {
- if len(tabs) <= 1 {
- return
- }
+func TabbarString() (string, map[int]int) {
str := ""
+ indicies := make(map[int]int)
+ indicies[0] = 0
for i, t := range tabs {
if i == curTab {
str += "["
} else {
str += " "
}
+ indicies[len(str)-1] = i + 1
str += " "
}
+ return str, indicies
+}
+
+func TabbarHandleMouseEvent(event tcell.Event) bool {
+ if len(tabs) <= 1 {
+ return false
+ }
+
+ switch e := event.(type) {
+ case *tcell.EventMouse:
+ button := e.Buttons()
+ if button == tcell.Button1 {
+ x, y := e.Position()
+ if y != 0 {
+ return false
+ }
+ str, indicies := TabbarString()
+ if x >= len(str) {
+ return false
+ }
+ var tabnum int
+ var keys []int
+ for k := range indicies {
+ keys = append(keys, k)
+ }
+ sort.Ints(keys)
+ for _, k := range keys {
+ if x <= k {
+ tabnum = indicies[k] - 1
+ break
+ }
+ }
+ curTab = tabnum
+ return true
+ }
+ }
+
+ return false
+}
+
+func DisplayTabs() {
+ if len(tabs) <= 1 {
+ return
+ }
+
+ str, _ := TabbarString()
tabBarStyle := defStyle.Reverse(true)
if style, ok := colorscheme["tabbar"]; ok {