]> git.lizzy.rs Git - micro.git/commitdiff
Fix non-working split resize with mouse drag (#1811)
authorDmitry Maluka <dmitrymaluka@gmail.com>
Tue, 4 Aug 2020 22:37:19 +0000 (00:37 +0200)
committerGitHub <noreply@github.com>
Tue, 4 Aug 2020 22:37:19 +0000 (18:37 -0400)
Fix the 2nd part of #1773: resize via mouse drag doesn't work if the
split on the left contains other splits, i.e. is not a leaf node.

The problem is that only leaf nodes have unique id. For non-leaf nodes
ID() returns 0. So we shouldn't search the node by id.
So replace GetMouseSplitID() with GetMouseSplitNode().

internal/action/tab.go
internal/display/uiwindow.go

index 9d5d82be1d3b863060d073d40d8aa154c63b1353..adefe5240a1d922377f75a07b629c0950fb07b7c 100644 (file)
@@ -220,9 +220,8 @@ func (t *Tab) HandleEvent(event tcell.Event) {
                        }
 
                        if wasReleased {
-                               resizeID := t.GetMouseSplitID(buffer.Loc{mx, my})
-                               if resizeID != 0 {
-                                       t.resizing = t.GetNode(uint64(resizeID))
+                               t.resizing = t.GetMouseSplitNode(buffer.Loc{mx, my})
+                               if t.resizing != nil {
                                        return
                                }
 
index 19ce872bd670f35765badca16be308489258eed3..60c4dc7e8995b2583be65f3a30934c7b327437eb 100644 (file)
@@ -53,32 +53,32 @@ func (w *UIWindow) Display() {
        w.drawNode(w.root)
 }
 
-func (w *UIWindow) GetMouseSplitID(vloc buffer.Loc) uint64 {
-       var mouseLoc func(*views.Node) uint64
-       mouseLoc = func(n *views.Node) uint64 {
+func (w *UIWindow) GetMouseSplitNode(vloc buffer.Loc) *views.Node {
+       var mouseLoc func(*views.Node) *views.Node
+       mouseLoc = func(n *views.Node) *views.Node {
                cs := n.Children()
                for i, c := range cs {
                        if c.Kind == views.STVert {
                                if i != len(cs)-1 {
                                        if vloc.X == c.X+c.W && vloc.Y >= c.Y && vloc.Y < c.Y+c.H {
-                                               return c.ID()
+                                               return c
                                        }
                                }
                        } else if c.Kind == views.STHoriz {
                                if i != len(cs)-1 {
                                        if vloc.Y == c.Y+c.H-1 && vloc.X >= c.X && vloc.X < c.X+c.W {
-                                               return c.ID()
+                                               return c
                                        }
                                }
                        }
                }
                for _, c := range cs {
                        m := mouseLoc(c)
-                       if m != 0 {
+                       if m != nil {
                                return m
                        }
                }
-               return 0
+               return nil
        }
        return mouseLoc(w.root)
 }