]> git.lizzy.rs Git - micro.git/commitdiff
Fix issues related to tabbar/infobar mouse events
authorZachary Yedidia <zyedidia@gmail.com>
Sat, 28 Dec 2019 20:56:56 +0000 (15:56 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Sat, 28 Dec 2019 20:56:56 +0000 (15:56 -0500)
Fixes #1440

internal/action/bufpane.go
internal/action/tab.go

index 02b19e362555ef5b190393ad8808a177b88cc5ab..451fc84060265e130ea71eeeda17317b61928032 100644 (file)
@@ -280,14 +280,27 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
                        h.DoRuneInsert(e.Rune())
                }
        case *tcell.EventMouse:
+               cancel := false
                switch e.Buttons() {
+               case tcell.Button1:
+                       _, my := e.Position()
+                       if h.Buf.Settings["statusline"].(bool) && my >= h.GetView().Y+h.GetView().Height-1 {
+                               cancel = true
+                       }
                case tcell.ButtonNone:
                        // Mouse event with no click
                        if !h.mouseReleased {
                                // Mouse was just released
 
-                               mx, my := e.Position()
-                               mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
+                               // mx, my := e.Position()
+                               // mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
+
+                               // we could finish the selection based on the release location as described
+                               // below but when the mouse click is within the scroll margin this will
+                               // cause a scroll and selection even for a simple mouse click which is
+                               // not good
+                               // for terminals that don't support mouse motion events, selection via
+                               // the mouse won't work but this is ok
 
                                // Relocating here isn't really necessary because the cursor will
                                // be in the right place from the last mouse event
@@ -295,20 +308,22 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
                                // events, this still allows the user to make selections, except only after they
                                // release the mouse
 
-                               if !h.doubleClick && !h.tripleClick {
-                                       h.Cursor.Loc = mouseLoc
-                                       h.Cursor.SetSelectionEnd(h.Cursor.Loc)
-                                       h.Cursor.CopySelection("primary")
-                               }
+                               // if !h.doubleClick && !h.tripleClick {
+                               //      h.Cursor.Loc = mouseLoc
+                               //      h.Cursor.SetSelectionEnd(h.Cursor.Loc)
+                               //      h.Cursor.CopySelection("primary")
+                               // }
                                h.mouseReleased = true
                        }
                }
 
-               me := MouseEvent{
-                       btn: e.Buttons(),
-                       mod: e.Modifiers(),
+               if !cancel {
+                       me := MouseEvent{
+                               btn: e.Buttons(),
+                               mod: e.Modifiers(),
+                       }
+                       h.DoMouseEvent(me, e)
                }
-               h.DoMouseEvent(me, e)
        }
        h.Buf.MergeCursors()
 
index 84a07653ec117ff25c9ced4b88a93b75cc77ed36..ba29a2821856845d76af973e0fe28c186a1bb869 100644 (file)
@@ -103,10 +103,15 @@ func (t *TabList) HandleEvent(event tcell.Event) {
                mx, my := e.Position()
                switch e.Buttons() {
                case tcell.Button1:
-                       ind := t.LocFromVisual(buffer.Loc{mx, my})
-                       if ind != -1 {
-                               t.SetActive(ind)
-                               return
+                       if len(t.List) > 1 {
+                               ind := t.LocFromVisual(buffer.Loc{mx, my})
+                               if ind != -1 {
+                                       t.SetActive(ind)
+                                       return
+                               }
+                               if my == 0 {
+                                       return
+                               }
                        }
                case tcell.WheelUp:
                        if my == t.Y {