Browse Source

fix: word wrapping with hyphens

adamdotdevin 6 tháng trước cách đây
mục cha
commit
aae354c951

+ 3 - 1
packages/tui/internal/components/chat/message.go

@@ -325,7 +325,9 @@ func renderText(
 
 		// wrap styled text
 		styledText := result.String()
-		wrappedText := ansi.WordwrapWc(styledText, width-6, " -")
+		styledText = strings.ReplaceAll(styledText, "-", "\u2011")
+		wrappedText := ansi.WordwrapWc(styledText, width-6, " ")
+		wrappedText = strings.ReplaceAll(wrappedText, "\u2011", "-")
 		content = base.Width(width - 6).Render(wrappedText)
 	}
 

+ 2 - 0
packages/tui/internal/util/file.go

@@ -85,6 +85,7 @@ func Extension(path string) string {
 func ToMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
 	r := styles.GetMarkdownRenderer(width-6, backgroundColor)
 	content = strings.ReplaceAll(content, RootPath+"/", "")
+	content = strings.ReplaceAll(content, "-", "\u2011")
 	rendered, _ := r.Render(content)
 	lines := strings.Split(rendered, "\n")
 
@@ -105,5 +106,6 @@ func ToMarkdown(content string, width int, backgroundColor compat.AdaptiveColor)
 		}
 	}
 	content = strings.Join(lines, "\n")
+	content = strings.ReplaceAll(content, "\u2011", "-")
 	return strings.TrimSuffix(content, "\n")
 }