From 6858497999286700603b8cf54741d13269e7736c Mon Sep 17 00:00:00 2001 From: citrons Date: Sun, 1 Jun 2025 10:03:16 -0500 Subject: fix line wrapping bug --- tui/layout.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tui') diff --git a/tui/layout.go b/tui/layout.go index e2c3e0f..1413243 100644 --- a/tui/layout.go +++ b/tui/layout.go @@ -191,13 +191,15 @@ func (b *Box) computeText(axis int) { for _, t := range b.text { g := uniseg.NewGraphemes(t.text) for g.Next() { - line += g.Width() - if g.LineBreak() == uniseg.LineMustBreak { + if g.Str() == "\n" { maxLine = max(maxLine, line) line = 0 + } else { + line += g.Width() } } } + maxLine = max(maxLine, line) if b.Width == TextSize { b.computedSize[axis] = maxLine + b.marginsSize(axis) } @@ -216,7 +218,7 @@ func (b *Box) computeText(axis int) { word.add(g.Str(), run.style) if word.width >= limit { line.addRuns(word.flush()) - } else if line.width + word.width >= limit { + } else if line.width + word.width > limit { b.computedLines = append(b.computedLines, line.flush()) } if unicode.IsSpace(g.Runes()[0]) { -- cgit v1.2.3