From edf63666b85386e757b8d5cbbd41d5dcefe65d61 Mon Sep 17 00:00:00 2001 From: Gustave-241021 <2909789120@qq.com> Date: Mon, 8 Dec 2025 22:19:18 +0800 Subject: [PATCH] fix: use visual width instead of byte length for text truncation (#1562) --- internal/tui/components/chat/messages/renderer.go | 2 +- internal/tui/components/chat/messages/tool.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/tui/components/chat/messages/renderer.go b/internal/tui/components/chat/messages/renderer.go index 72631d2a8e5b77b7e7e664798735a1e134fad6d5..f75a576d91af7f24f8c32df054d5cd24fd80f58c 100644 --- a/internal/tui/components/chat/messages/renderer.go +++ b/internal/tui/components/chat/messages/renderer.go @@ -1025,7 +1025,7 @@ func renderPlainContent(v *toolCallCmp, content string) string { } ln = ansiext.Escape(ln) ln = " " + ln - if len(ln) > width { + if lipgloss.Width(ln) > width { ln = v.fit(ln, width) } out = append(out, t.S().Muted. diff --git a/internal/tui/components/chat/messages/tool.go b/internal/tui/components/chat/messages/tool.go index 123d02e63c76687d4a722957a5b363082c9a3670..b72ae7afd22fd64a3839d3187f79400d7a2f30ba 100644 --- a/internal/tui/components/chat/messages/tool.go +++ b/internal/tui/components/chat/messages/tool.go @@ -790,6 +790,9 @@ func (m *toolCallCmp) textWidth() int { // fit truncates content to fit within the specified width with ellipsis func (m *toolCallCmp) fit(content string, width int) string { + if lipgloss.Width(content) <= width { + return content + } t := styles.CurrentTheme() lineStyle := t.S().Muted dots := lineStyle.Render("…")