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