From e7a4c61b637612aced4f0176ee5120986a22f9cc Mon Sep 17 00:00:00 2001 From: Petter Rodhelind Date: Wed, 3 Mar 2021 16:42:43 +0100 Subject: Fix middle click selection. --- ui/tcell/view.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ui/tcell/view.go b/ui/tcell/view.go index ecd5aa4..73f1453 100644 --- a/ui/tcell/view.go +++ b/ui/tcell/view.go @@ -558,10 +558,10 @@ func RuneWidth(r rune) int { func ButtonSecondary(v *View, mx, my int) { pos := v.XYToOffset(mx, my) - // if we clicked inside a current selection, open that one + // if we clicked outside a current selection, open that one q0, q1 := v.text.Dot() if pos < q0 || pos > q1 || q0 == q1 { - // otherwise, select everything inside surround spaces and open that + // select everything inside surround spaces and open that p := pos - v.text.PrevSpace(pos) n := pos + v.text.NextSpace(pos) v.text.SetDot(p, n) @@ -596,19 +596,21 @@ func ButtonSecondary(v *View, mx, my int) { func ButtonMiddle(v *View, mx, my int) { pos := v.XYToOffset(mx, my) - // if we clicked inside a current selection, run that one + // if we clicked outside a current selection, run that one q0, q1 := v.text.Dot() - if pos >= q0 && pos <= q1 && q0 != q1 { - Cmd(v.text.ReadDot()) - return + if pos < q0 || pos > q1 || q0 == q1 { + // select everything inside surround spaces and run that + p := pos - v.text.PrevSpace(pos) + n := pos + v.text.NextSpace(pos) + v.text.SetDot(p, n) } - // otherwise, select non-space chars under mouse and run that - p := pos - v.text.PrevSpace(pos) - n := pos + v.text.NextSpace(pos) - v.text.SetDot(p, n) - fn := strings.Trim(v.text.ReadDot(), "\n\t ") + str := strings.Trim(v.text.ReadDot(), "\n\t ") v.text.SetDot(q0, q1) - Cmd(fn) + + output := Cmd(str) + if output != "" { + printMsg(output) + } return } -- cgit v1.2.3