Move the click-path hyperlink lookup onto View

Reading a view's internal buffer belongs on the view itself, next to
findHyperlinkAt, rather than in the event loop; and the view is where the
lock that guards that buffer can be taken.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-08-15 15:30:27 +02:00
co-authored by Claude Opus 5
parent d65ee95942
commit e3fe321080
2 changed files with 12 additions and 4 deletions
+2 -4
View File
@@ -1763,10 +1763,8 @@ func (g *Gui) onKey(ev *GocuiEvent) error {
}
if ev.Key.KeyName() == MouseLeft && (ev.Key.Mod()&ModMotion) == 0 && !v.Editable && g.openHyperlink != nil {
if newY >= 0 && newY <= len(v.viewLines)-1 && newX >= 0 && newX <= len(v.viewLines[newY].line)-1 {
if link := v.viewLines[newY].line[newX].hyperlink; link != "" {
return g.openHyperlink(link, v.name)
}
if link := v.hyperlinkAt(newX, newY); link != "" {
return g.openHyperlink(link, v.name)
}
}
+10
View File
@@ -2116,6 +2116,16 @@ func (v *View) onMouseMove(x int, y int) {
}
}
// hyperlinkAt returns the hyperlink at the given position of the view's
// content, or an empty string if there is none.
func (v *View) hyperlinkAt(x, y int) string {
if y < 0 || y >= len(v.viewLines) || x < 0 || x >= len(v.viewLines[y].line) {
return ""
}
return v.viewLines[y].line[x].hyperlink
}
func (v *View) findHyperlinkAt(x, y int) *SearchPosition {
linkStr := v.viewLines[y].line[x].hyperlink
if linkStr == "" {