From a401d7aaff5c93ee7bd8083a078849a9e41798f2 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Sat, 26 Feb 2022 13:46:14 -0500 Subject: [PATCH] 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 --- widget/editor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/editor.go b/widget/editor.go index 8fd9e1a2..2e212561 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -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.