From 7abcad1f4139cd7c59e97efeccf83bf82963e80a Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 28 Jul 2024 11:30:20 -0700 Subject: [PATCH] Try #2 of temp fix for #4998 --- widget/richtext.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/widget/richtext.go b/widget/richtext.go index 04a7e99e95..bc7afd2334 100644 --- a/widget/richtext.go +++ b/widget/richtext.go @@ -958,14 +958,6 @@ 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) @@ -1071,9 +1063,19 @@ 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)}) + // Supersonic: tmp fix for https://github.com/fyne-io/fyne/issues/4998 + high = binarySearch(widthChecker, low, high) + ellipsis := high < len(text) + if ellipsis && high > 0 && low < high { + // trim off up to 2 characters to make room for ellipsis + ellipsisWidth := fyne.MeasureText("…", seg.size(), seg.Style.TextStyle).Width + if fyne.MeasureText(string(text[high-1:high]), seg.size(), seg.Style.TextStyle).Width < ellipsisWidth && high > 1 && low < high-1 { + high -= 2 + } else { + high -= 1 + } + } + bounds = append(bounds, rowBoundary{[]RichTextSegment{seg}, reuse, low, high, ellipsis}) reuse++ /* orig Fyne code: