]> git.lizzy.rs Git - micro.git/commitdiff
Make tabs respond to mouse events
authorZachary Yedidia <zyedidia@gmail.com>
Wed, 8 Jun 2016 21:47:48 +0000 (17:47 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 8 Jun 2016 21:47:48 +0000 (17:47 -0400)
cmd/micro/bindings.go
cmd/micro/micro.go
cmd/micro/tab.go
runtime/help/help.md

index 14de9ac507ffd81b6a1c2c8684bcf67d85585cc9..ff88826181390fac4fdf14d8ef8b59681b1f6a8c 100644 (file)
@@ -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
index 4c9ea68f8c258523434ac4f51d16f52702a1b936..3ff79e6d82959923e09a3758ec15760c53492b41 100644 (file)
@@ -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
index d4d4d498fd8046b82891966afd1d6b6ae4325264..cada1b726c1672cf5f326ba7ee3e2edbdf2cd0b6 100644 (file)
@@ -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 {
index 79f017c2f1806e0e8872a7b99e3b3ec0b177844f..02ecffcafbb2472c2d4ff44276e3f5477573fcea 100644 (file)
@@ -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",