Skip to content

fix(tui): fix paste rendering for long/Unicode text#6

Merged
markm39 merged 1 commit into
masterfrom
worktree-fix+paste-input-rendering
Mar 28, 2026
Merged

fix(tui): fix paste rendering for long/Unicode text#6
markm39 merged 1 commit into
masterfrom
worktree-fix+paste-input-rendering

Conversation

@markm39
Copy link
Copy Markdown
Collaborator

@markm39 markm39 commented Mar 28, 2026

Summary

  • Fix Unicode width mismatch in scroll calculation that caused garbled display after pasting text with Unicode characters
  • Collapse long single-line pastes (>120 chars) into [Pasted text] markers, same as multi-line pastes
  • Strip carriage returns from pasted text to normalize Windows line endings

Test plan

  • cargo clippy --workspace -- -D warnings
  • cargo test --workspace
  • Manual: paste long physics problem text from web -- shows marker instead of garbled fragments
  • Manual: paste short text (<120 chars) -- inlines normally
  • Manual: cursor stays visible after paste

Two issues fixed:

1. Unicode width mismatch: cursor_visual_row and compute_input_height
   used col+=1 per character, but ratatui wraps using actual Unicode
   widths. This caused scroll offset miscalculation, displaying garbled
   fragments after pasting text with wide/zero-width Unicode chars.
   Now uses unicode_width::UnicodeWidthChar for accurate column tracking.

2. Long single-line pastes: only multi-line pastes were collapsed into
   [Pasted text] markers. Long single-line pastes (>120 chars, common
   from web/PDF copy) were inlined, causing the cursor to escape the
   visible input area. Now collapses any paste over 120 chars.

Also strips carriage returns (\r) from pasted text to normalize
Windows-style line endings.
@markm39 markm39 merged commit f85016e into master Mar 28, 2026
3 checks passed
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.

1 participant