From 9d79348686d18d884b533ae0c0b47d9969eb8606 Mon Sep 17 00:00:00 2001 From: DevHegemony Date: Thu, 28 Mar 2024 20:08:59 -0400 Subject: [PATCH] fixing #959 textview mouse out of bounds fix --- box.go | 7 +++++++ textview.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/box.go b/box.go index 78fe4bf..ec7ec91 100644 --- a/box.go +++ b/box.go @@ -260,6 +260,13 @@ func (b *Box) InRect(x, y int) bool { return x >= rectX && x < rectX+width && y >= rectY && y < rectY+height } +// InRect returns true if the given coordinate is within the bounds of the box's +// rectangle. +func (b *Box) InInnerRect(x, y int) bool { + rectX, rectY, width, height := b.GetInnerRect() + return x >= rectX && x < rectX+width && y >= rectY && y < rectY+height +} + // GetMouseCapture returns the function installed with SetMouseCapture() or nil // if no such function has been installed. func (b *Box) GetMouseCapture() func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse) { diff --git a/textview.go b/textview.go index 743bd6d..bd3ea0e 100644 --- a/textview.go +++ b/textview.go @@ -1377,7 +1377,7 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou setFocus(t) consumed = true case MouseLeftClick: - if t.regionTags { + if t.regionTags && t.InInnerRect(x, y) { // Find a region to highlight. x -= rectX y -= rectY