From cf8935be518e2316ea324b0888d165531663bd73 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Fri, 5 Jun 2026 20:22:34 -0300 Subject: [PATCH] fix(tui): bound stream source remapping --- codex-rs/tui/src/streaming/controller.rs | 45 ++++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/codex-rs/tui/src/streaming/controller.rs b/codex-rs/tui/src/streaming/controller.rs index d76a8459af..8b1f7d53bc 100644 --- a/codex-rs/tui/src/streaming/controller.rs +++ b/codex-rs/tui/src/streaming/controller.rs @@ -667,12 +667,13 @@ impl StreamCore { boundaries.push(self.raw_source.len()); } - for boundary in boundaries { - if self.render_source(&self.raw_source[..boundary]).len() >= rendered_len { - return boundary; - } - } - self.raw_source.len() + let idx = boundaries.partition_point(|boundary| { + self.render_source(&self.raw_source[..*boundary]).len() < rendered_len + }); + boundaries + .get(idx) + .copied() + .unwrap_or(self.raw_source.len()) } fn partial_source_line_after_rendered_len( @@ -838,7 +839,7 @@ fn visible_text_source_boundary(source: &str, visible_prefix: &str) -> Option