]> git.lizzy.rs Git - micro.git/blobdiff - internal/action/tab.go
Fix v2 import path for go mod
[micro.git] / internal / action / tab.go
index ba29a2821856845d76af973e0fe28c186a1bb869..9d5d82be1d3b863060d073d40d8aa154c63b1353 100644 (file)
@@ -1,11 +1,11 @@
 package action
 
 import (
-       "github.com/zyedidia/micro/internal/buffer"
-       "github.com/zyedidia/micro/internal/config"
-       "github.com/zyedidia/micro/internal/display"
-       "github.com/zyedidia/micro/internal/screen"
-       "github.com/zyedidia/micro/internal/views"
+       "github.com/zyedidia/micro/v2/internal/buffer"
+       "github.com/zyedidia/micro/v2/internal/config"
+       "github.com/zyedidia/micro/v2/internal/display"
+       "github.com/zyedidia/micro/v2/internal/screen"
+       "github.com/zyedidia/micro/v2/internal/views"
        "github.com/zyedidia/tcell"
 )
 
@@ -91,6 +91,7 @@ func (t *TabList) Resize() {
                t.List[0].Node.Resize(w, h-iOffset)
                t.List[0].Resize()
        }
+       t.TabWindow.Resize(w, h)
 }
 
 // HandleEvent checks for a resize event or a mouse event on the tab bar
@@ -103,6 +104,13 @@ func (t *TabList) HandleEvent(event tcell.Event) {
                mx, my := e.Position()
                switch e.Buttons() {
                case tcell.Button1:
+                       if my == t.Y && mx == 0 {
+                               t.Scroll(-4)
+                               return
+                       } else if my == t.Y && mx == t.Width-1 {
+                               t.Scroll(4)
+                               return
+                       }
                        if len(t.List) > 1 {
                                ind := t.LocFromVisual(buffer.Loc{mx, my})
                                if ind != -1 {
@@ -158,6 +166,8 @@ type Tab struct {
        active int
 
        resizing *views.Node // node currently being resized
+       // captures whether the mouse is released
+       release bool
 }
 
 // NewTabFromBuffer creates a new tab from the given buffer
@@ -166,7 +176,7 @@ func NewTabFromBuffer(x, y, width, height int, b *buffer.Buffer) *Tab {
        t.Node = views.NewRoot(x, y, width, height)
        t.UIWindow = display.NewUIWindow(t.Node)
 
-       e := NewBufPaneFromBuf(b)
+       e := NewBufPaneFromBuf(b, t)
        e.SetID(t.ID())
 
        t.Panes = append(t.Panes, e)
@@ -177,7 +187,7 @@ func NewTabFromPane(x, y, width, height int, pane Pane) *Tab {
        t := new(Tab)
        t.Node = views.NewRoot(x, y, width, height)
        t.UIWindow = display.NewUIWindow(t.Node)
-
+       pane.SetTab(t)
        pane.SetID(t.ID())
 
        t.Panes = append(t.Panes, pane)
@@ -195,7 +205,8 @@ func (t *Tab) HandleEvent(event tcell.Event) {
                mx, my := e.Position()
                switch e.Buttons() {
                case tcell.Button1:
-                       resizeID := t.GetMouseSplitID(buffer.Loc{mx, my})
+                       wasReleased := t.release
+                       t.release = false
                        if t.resizing != nil {
                                var size int
                                if t.resizing.Kind == views.STVert {
@@ -208,21 +219,25 @@ func (t *Tab) HandleEvent(event tcell.Event) {
                                return
                        }
 
-                       if resizeID != 0 {
-                               t.resizing = t.GetNode(uint64(resizeID))
-                               return
-                       }
+                       if wasReleased {
+                               resizeID := t.GetMouseSplitID(buffer.Loc{mx, my})
+                               if resizeID != 0 {
+                                       t.resizing = t.GetNode(uint64(resizeID))
+                                       return
+                               }
 
-                       for i, p := range t.Panes {
-                               v := p.GetView()
-                               inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height
-                               if inpane {
-                                       t.SetActive(i)
-                                       break
+                               for i, p := range t.Panes {
+                                       v := p.GetView()
+                                       inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height
+                                       if inpane {
+                                               t.SetActive(i)
+                                               break
+                                       }
                                }
                        }
                case tcell.ButtonNone:
                        t.resizing = nil
+                       t.release = true
                default:
                        for _, p := range t.Panes {
                                v := p.GetView()
@@ -283,6 +298,10 @@ func (t *Tab) Resize() {
 }
 
 // CurPane returns the currently active pane
-func (t *Tab) CurPane() Pane {
-       return t.Panes[t.active]
+func (t *Tab) CurPane() *BufPane {
+       p, ok := t.Panes[t.active].(*BufPane)
+       if !ok {
+               return nil
+       }
+       return p
 }