widget: fix Editor.CaretCoords when scrolled

This commit fixes the position returned by Editor.CaretCoords
to account for the scroll position of the editor. Without this
change, the returned coordinates can easily overflow the boundaries
of the editor widget when it has been scrolled on either axis.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2022-02-26 13:46:14 -05:00
committed by Elias Naur
parent 79bfd3adbd
commit a401d7aaff
+1 -1
View File
@@ -908,7 +908,7 @@ func (e *Editor) CaretPos() (line, col int) {
// editor itself.
func (e *Editor) CaretCoords() f32.Point {
caret := e.closestPosition(combinedPos{runes: e.caret.start})
return f32.Pt(float32(caret.x)/64, float32(caret.y))
return f32.Pt(float32(caret.x)/64-float32(e.scrollOff.X), float32(caret.y-e.scrollOff.Y))
}
// indexPosition returns the latest position from the index no later than pos.