From 844b5d8d0d094a324a63deda454455c2ec62565e Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Fri, 3 Oct 2025 10:25:30 -0700 Subject: [PATCH] tui: wrapping bugfix --- codex-rs/tui/src/history_cell.rs | 3 ++- codex-rs/tui/src/wrapping.rs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index 4bab8afb70b4..2e3a2d297697 100644 --- a/codex-rs/tui/src/history_cell.rs +++ b/codex-rs/tui/src/history_cell.rs @@ -104,7 +104,8 @@ impl HistoryCell for UserHistoryCell { .lines() .map(|l| Line::from(l).style(style)) .collect::>(), - RtOptions::new(wrap_width as usize), + // Wrap algorithm matches textarea.rs. + RtOptions::new(wrap_width as usize).wrap_algorithm(textwrap::WrapAlgorithm::FirstFit), ); lines.push(Line::from("").style(style)); diff --git a/codex-rs/tui/src/wrapping.rs b/codex-rs/tui/src/wrapping.rs index da79f036b4ad..70ca2e46ca93 100644 --- a/codex-rs/tui/src/wrapping.rs +++ b/codex-rs/tui/src/wrapping.rs @@ -2,6 +2,7 @@ use ratatui::text::Line; use ratatui::text::Span; use std::ops::Range; use textwrap::Options; +use textwrap::wrap_algorithms::Penalties; use crate::render::line_utils::push_owned_lines; @@ -90,7 +91,11 @@ impl<'a> RtOptions<'a> { subsequent_indent: Line::default(), break_words: true, word_separator: textwrap::WordSeparator::new(), - wrap_algorithm: textwrap::WrapAlgorithm::new(), + wrap_algorithm: textwrap::WrapAlgorithm::OptimalFit(Penalties { + // ~infinite overflow penalty, we never want to overflow a line. + overflow_penalty: usize::MAX / 4, + ..Default::default() + }), word_splitter: textwrap::WordSplitter::HyphenSplitter, } }