Skip to content

Commit

Permalink
Fix accidental truncation when multi-byte runes had ellipsis trunc
Browse files Browse the repository at this point in the history
Fixes #4283
  • Loading branch information
andydotxyz committed Oct 3, 2023
1 parent df6e029 commit ac32047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,8 @@ func lineBounds(seg *TextSegment, wrap fyne.TextWrap, trunc fyne.TextTruncation,
}
default:
if trunc == fyne.TextTruncateEllipsis {
txt := seg.Text[low:high]
end, full := truncateLimit(txt, seg.Visual().(*canvas.Text), int(measureWidth), []rune{'…'})
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++
Expand Down
10 changes: 10 additions & 0 deletions widget/richtext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,16 @@ func TestText_lineBounds(t *testing.T) {
},
ellipses: 1,
},
{
name: "Multi_byte_ellipsis_not_truncated",
text: "🪃 234",
trunc: fyne.TextTruncateEllipsis,
wrap: fyne.TextWrapOff,
want: [][2]int{
{0, 5},
},
ellipses: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ac32047

Please sign in to comment.