From b46c0f5907936194673ddaa254f2fb9e9a57e085 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Mon, 17 Oct 2022 08:56:24 -0400 Subject: [PATCH] widget: use reliable text direction checks, not heuristics This commit switches the way in which the editor and helper functions check for RTL text from a heuristic to using the actual text direction. Signed-off-by: Chris Waldon --- widget/editor.go | 3 --- widget/label.go | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/widget/editor.go b/widget/editor.go index dbf5a345..c207262e 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -794,9 +794,6 @@ func (e *Editor) PaintText(gtx layout.Context) { start, end := clipLine(e.lines, e.Alignment, e.viewSize.X, cl, pos) line := e.lines[start.lineCol.Y] off := image.Point{X: start.x.Floor(), Y: start.y}.Sub(scroll) - if start.lineCol.X > end.lineCol.X { - start, end = end, start - } l := subLayout(line, start, end) t := op.Offset(off).Push(gtx.Ops) diff --git a/widget/label.go b/widget/label.go index 8d77774f..08b6139a 100644 --- a/widget/label.go +++ b/widget/label.go @@ -68,13 +68,9 @@ func clipLine(lines []text.Line, alignment text.Alignment, width int, clip image } func subLayout(line text.Line, start, end combinedPos) text.Layout { - if start.lineCol.X == line.Layout.Runes.Count { - return text.Layout{} - } - startCluster := clusterIndexFor(line, start.lineCol.X, start.clusterIndex) endCluster := clusterIndexFor(line, end.lineCol.X, end.clusterIndex) - if startCluster > endCluster { + if line.Layout.Direction.Progression() == system.TowardOrigin { startCluster, endCluster = endCluster, startCluster } return line.Layout.Slice(startCluster, endCluster) -- 2.45.2