fixing #959 textview mouse out of bounds fix

This commit is contained in:
DevHegemony 2024-03-28 20:08:59 -04:00
parent e804876934
commit 9d79348686
2 changed files with 8 additions and 1 deletions

7
box.go
View File

@ -260,6 +260,13 @@ func (b *Box) InRect(x, y int) bool {
return x >= rectX && x < rectX+width && y >= rectY && y < rectY+height 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 // GetMouseCapture returns the function installed with SetMouseCapture() or nil
// if no such function has been installed. // if no such function has been installed.
func (b *Box) GetMouseCapture() func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse) { func (b *Box) GetMouseCapture() func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse) {

View File

@ -1377,7 +1377,7 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou
setFocus(t) setFocus(t)
consumed = true consumed = true
case MouseLeftClick: case MouseLeftClick:
if t.regionTags { if t.regionTags && t.InInnerRect(x, y) {
// Find a region to highlight. // Find a region to highlight.
x -= rectX x -= rectX
y -= rectY y -= rectY