From 2fe69916fa63ab1d6ecd2f9cdee9957d6029908b Mon Sep 17 00:00:00 2001 From: coloursofnoise Date: Tue, 23 Nov 2021 14:57:06 -0800 Subject: [PATCH] Add View.RemoveCursor to deselect all lines --- _examples/mouse.go | 2 ++ gui.go | 5 +++++ view.go | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/_examples/mouse.go b/_examples/mouse.go index b6c55ec..c23b332 100644 --- a/_examples/mouse.go +++ b/_examples/mouse.go @@ -39,6 +39,7 @@ func layout(g *gocui.Gui) error { return err } v.Highlight = true + v.RemoveCursor() v.SelBgColor = gocui.ColorGreen v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Button 1 - line 1") @@ -54,6 +55,7 @@ func layout(g *gocui.Gui) error { return err } v.Highlight = true + v.RemoveCursor() v.SelBgColor = gocui.ColorGreen v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Button 2 - line 1") diff --git a/gui.go b/gui.go index 76bcb5c..b11eb51 100644 --- a/gui.go +++ b/gui.go @@ -75,6 +75,7 @@ type Gui struct { blacklist []Key testCounter int // used for testing synchronization testNotify chan struct{} + mouseView *View // last view selected by mouse if enabled // BgColor and FgColor allow to configure the background and foreground // colors of the GUI. @@ -880,8 +881,12 @@ func (g *Gui) onKey(ev *gocuiEvent) error { g.currentView.Editor.Edit(g.currentView, Key(ev.Key), ev.Ch, Modifier(ev.Mod)) } case eventMouse: + if g.mouseView != nil { + g.mouseView.RemoveCursor() + } mx, my := ev.MouseX, ev.MouseY v, err := g.ViewByPosition(mx, my) + g.mouseView = v if err != nil { break } diff --git a/view.go b/view.go index f22ddf0..cf47c1e 100644 --- a/view.go +++ b/view.go @@ -269,6 +269,10 @@ func (v *View) SetCursor(x, y int) error { return v.SetCursorUnrestricted(x, y) } +func (v *View) RemoveCursor() { + v.cx, v.cy = -1, -1 +} + // Cursor returns the cursor position of the view. func (v *View) Cursor() (x, y int) { return v.cx, v.cy -- 2.33.0