mirror of
https://github.com/zyedidia/micro
synced 2024-09-30 05:06:02 +00:00
Make tabs respond to mouse events
This commit is contained in:
parent
059a5c3b89
commit
a79e964cb6
|
@ -1097,8 +1097,8 @@ func (v *View) Quit() bool {
|
|||
curTab--
|
||||
}
|
||||
if curTab == 0 {
|
||||
tab := tabs[curTab]
|
||||
tab.views[tab.curView].Resize(screen.Size())
|
||||
CurView().Resize(screen.Size())
|
||||
CurView().matches = Match(CurView())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1114,6 +1114,13 @@ func (v *View) AddTab() bool {
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -1121,14 +1128,14 @@ func (v *View) LastTab() bool {
|
|||
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
|
||||
|
|
|
@ -257,6 +257,9 @@ func main() {
|
|||
|
||||
// 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
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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
|
||||
|
@ -30,11 +36,10 @@ func CurView() *View {
|
|||
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 += "["
|
||||
|
@ -47,8 +52,55 @@ func DisplayTabs() {
|
|||
} 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 {
|
||||
|
|
|
@ -63,6 +63,7 @@ you can rebind them to your liking.
|
|||
"CtrlD": "DuplicateLine",
|
||||
"CtrlV": "Paste",
|
||||
"CtrlA": "SelectAll",
|
||||
"CtrlT": "AddTab"
|
||||
"Home": "Start",
|
||||
"End": "End",
|
||||
"PageUp": "CursorPageUp",
|
||||
|
|
Loading…
Reference in a new issue