From 91d99b12cdf3efa94a64fafdbbd4e5d0d3ff3f21 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 28 Jul 2024 09:55:21 -0700 Subject: [PATCH] Tmp fix for #4998 --- widget/richtext.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/widget/richtext.go b/widget/richtext.go index 73af8ce5ba..04a7e99e95 100644 --- a/widget/richtext.go +++ b/widget/richtext.go @@ -958,6 +958,14 @@ func lineBounds(seg *TextSegment, wrap fyne.TextWrap, trunc fyne.TextTruncation, widthChecker := func(low int, high int) bool { return measurer(text[low:high]).Width <= measureWidth } + // Supersonic: temporary fix for https://github.com/fyne-io/fyne/issues/4998 + widthCheckerEllipsis := func(low, high int) bool { + if low == 0 && high == len(text)-1 { + return measurer(text[low:high]).Width <= measureWidth + } + return measurer(text[low:high]).Width+ + measurer([]rune{'…'}).Width <= measureWidth + } reuse := 0 yPos := float32(0) @@ -1063,11 +1071,18 @@ func lineBounds(seg *TextSegment, wrap fyne.TextWrap, trunc fyne.TextTruncation, } default: if trunc == fyne.TextTruncateEllipsis { + // Supersonic: temporary fix for https://github.com/fyne-io/fyne/issues/4998 + high = binarySearch(widthCheckerEllipsis, low, high) + bounds = append(bounds, rowBoundary{[]RichTextSegment{seg}, reuse, low, high, high < len(text)}) + reuse++ + + /* orig Fyne code: txt := []rune(seg.Text)[low:high] end, full := truncateLimit(string(txt), seg.Visual().(*canvas.Text), int(measureWidth), []rune{'…'}) high = low + end bounds = append(bounds, rowBoundary{[]RichTextSegment{seg}, reuse, low, high, !full}) reuse++ + */ } else if trunc == fyne.TextTruncateClip { high = binarySearch(widthChecker, low, high) bounds = append(bounds, rowBoundary{[]RichTextSegment{seg}, reuse, low, high, false})