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 <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2022-03-16 16:01:29 -04:00
committed by Elias Naur
parent eec78223d1
commit 1ad785658e
+5
View File
@@ -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