diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index 4bab8afb70..2e3a2d2976 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 da79f036b4..70ca2e46ca 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, } }