From 1ad785658e631e968cf2f5def94defbe2b580b76 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Wed, 16 Mar 2022 16:01:29 -0400 Subject: [PATCH] widget: optimize painting editor selection This commit introduces logic to skip painting the selection rectangle on lines prior to the line containing the beginning of the selection. Signed-off-by: Chris Waldon --- widget/editor.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/widget/editor.go b/widget/editor.go index 7e7c8f85..754bf19a 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -680,6 +680,11 @@ func (e *Editor) PaintSelection(gtx layout.Context) { for !posIsBelow(e.lines, pos, cl.Max.Y) { start, end := clipLine(e.lines, e.Alignment, e.viewSize.X, cl, pos) lineIdx := start.lineCol.Y + if lineIdx < caretStart.lineCol.Y { + // Line is before selection start; skip. + pos = e.closestPosition(combinedPos{lineCol: screenPos{Y: pos.lineCol.Y + 1}}) + continue + } if lineIdx > caretEnd.lineCol.Y { // Line is after selection end; we're done. return