From e4a85fc77921a088e1c1ce36e710f4a8b33354ff Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Thu, 7 Mar 2024 18:14:13 +0100 Subject: [PATCH] Mouse scrolling to the end turns tracking on. Resolves #945 --- textview.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/textview.go b/textview.go index 2ba9e65..e5c8846 100644 --- a/textview.go +++ b/textview.go @@ -1371,6 +1371,7 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou return false, nil } + rectX, rectY, width, height := t.GetInnerRect() switch action { case MouseLeftDown: setFocus(t) @@ -1378,7 +1379,6 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou case MouseLeftClick: if t.regionTags { // Find a region to highlight. - rectX, rectY, _, _ := t.GetInnerRect() x -= rectX y -= rectY var highlightedID string @@ -1404,6 +1404,15 @@ func (t *TextView) MouseHandler() func(action MouseAction, event *tcell.EventMou consumed = true case MouseScrollDown: t.lineOffset++ + if len(t.lineIndex)-t.lineOffset < height { + // If we scroll to the end, turn on tracking. + t.parseAhead(width, func(lineNumber int, line *textViewLine) bool { + return len(t.lineIndex)-t.lineOffset < height + }) + if len(t.lineIndex)-t.lineOffset < height { + t.trackEnd = true + } + } consumed = true }