Skip to content

fix: prevent sparse spacing in hyphenated words#1102

Merged
adamdotdevin merged 4 commits intoanomalyco:devfrom
monotykamary:fix/hyphen-word-wrapping
Jul 19, 2025
Merged

fix: prevent sparse spacing in hyphenated words#1102
adamdotdevin merged 4 commits intoanomalyco:devfrom
monotykamary:fix/hyphen-word-wrapping

Conversation

@monotykamary
Copy link
Copy Markdown
Contributor

@monotykamary monotykamary commented Jul 17, 2025

Summary

This PR fixes the sparse spacing issue that occurs when displaying hyphenated words like 'claude-code-action' in both Assistant and User messages in the TUI. Fixes #621.

Problem

Previously, hyphenated words would break at hyphens, creating sparse single-word lines that made the chat interface look broken and difficult to read.

Before:
image

Solution

After:
image

  • Assistant messages: Use non-breaking hyphens (U+2011) in markdown rendering to prevent word breaks at hyphens
  • User messages: Apply non-breaking hyphens before word wrapping and styling
  • Textarea component: Modified word boundary detection to treat hyphens as part of words
  • Width constraint: Maintained 86 character width limit with precise calculations

Changes Made

  1. packages/tui/internal/components/chat/message.go: Updated user message rendering to use non-breaking hyphens
  2. packages/tui/internal/components/textarea/textarea.go: Modified word boundary detection in textarea word wrapping
  3. packages/tui/internal/util/file.go: Enhanced markdown rendering with hyphen handling

Testing

  • Verified both Assistant and User messages display correctly
  • Confirmed 86 character width constraint is maintained
  • Tested with various hyphenated words and phrases
  • No visual regressions in existing functionality

This change significantly improves the readability of hyphenated content in the TUI without affecting any other functionality.

- Use non-breaking hyphens (U+2011) to prevent word breaks at hyphens
- Apply fix to both Assistant (markdown) and User (chat) messages
- Maintain 86 character width constraint
- Fix word boundary detection in textarea component

Fixes sparse single-word lines when displaying hyphenated words like 'claude-code-action'
Copy link
Copy Markdown
Member

@adamdotdevin adamdotdevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few questions, i'd love to have this fixed, just need to understand the implementation a little better

Comment thread packages/tui/internal/components/chat/message.go Outdated
Comment thread packages/tui/internal/components/chat/message.go Outdated
Comment thread packages/tui/internal/util/file.go Outdated
Comment thread packages/tui/internal/util/file.go Outdated
@monotykamary monotykamary force-pushed the fix/hyphen-word-wrapping branch from 8df9568 to ac501a1 Compare July 19, 2025 00:35
@monotykamary
Copy link
Copy Markdown
Contributor Author

monotykamary commented Jul 19, 2025

Now that you've pointed it out, I think there might be a more ergonomic way to do this 🤔
also now that we're going for a stretched look

- Extract hyphen preservation logic into reusable utility functions
- Replace magic numbers with dynamic style-based calculations
- Add GetMessageContainerFrame() and GetMarkdownContainerFrame() for DRY width calculations
- Simplify width calculations by removing outdated constraints
- Improve code maintainability with semantic function names and clear documentation

The hyphen handling now automatically adapts to style changes without manual updates.
@monotykamary
Copy link
Copy Markdown
Contributor Author

Before After
image image

@adamdotdevin adamdotdevin merged commit 2b44dbd into anomalyco:dev Jul 19, 2025
thdxr added a commit that referenced this pull request Jul 19, 2025
achembarpu pushed a commit to achembarpu/opencode that referenced this pull request Aug 4, 2025
achembarpu pushed a commit to achembarpu/opencode that referenced this pull request Aug 4, 2025
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrapping is off in terminal

2 participants