Lightweight coding agent that runs in your terminal
Rust
Hide Back to bottom when the current transcript tail is visible (#46902)
Felipe Couryeaff9a5f1461
diff --git a/codex-rs/tui/src/app/owned_transcript_tests.rs b/codex-rs/tui/src/app/owned_transcript_tests.rsindex 1d3cd14151..057885cac3 100644--- a/codex-rs/tui/src/app/owned_transcript_tests.rs+++ b/codex-rs/tui/src/app/owned_transcript_tests.rs@@ -238,7 +238,8 @@ async fn owned_transcript_reserves_a_row_above_the_composer() -> Result<()> {let gap = Rect::new(/*x*/ 0, bottom.y - 1, width, /*height*/ 1);let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal);let start = buffer.index_of(gap.x, gap.y);- if app.transcript_view.is_following() {+ // Both scenarios show the current tail, including the paused detailed view.+ if matches!(label, "Latest" | "Detailed") {assert_eq!(&buffer.content()[start..start + usize::from(width)],Buffer::empty(gap).content(),diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snapindex 1d301eae27..739480451e 100644--- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__owned_transcript_composer_gap.snap@@ -1,6 +1,6 @@---source: tui/src/app/owned_transcript_tests.rs-assertion_line: 220+assertion_line: 227expression: "snapshots.join(\"\\n\\n\")"---Latest@@ -59,7 +59,7 @@ Detailed- ↓ Back to bottom · esc+› preserved draftdiff --git a/codex-rs/tui/src/transcript_view/composer_gap_tests.rs b/codex-rs/tui/src/transcript_view/composer_gap_tests.rsindex 63007c9964..be82877dbb 100644--- a/codex-rs/tui/src/transcript_view/composer_gap_tests.rs+++ b/codex-rs/tui/src/transcript_view/composer_gap_tests.rs@@ -36,6 +36,7 @@ fn feedback_releases_navigation_targets_and_expiry_restores_them() {let mut view = TranscriptView::default();render(&mut view, &cells, /*width*/ 60, /*height*/ 3);view.scroll(&cells, /*rows*/ -2);+ render(&mut view, &cells, /*width*/ 60, /*height*/ 3);let area = Rect::new(/*x*/ 0, /*y*/ 3, /*width*/ 60, /*height*/ 1,);diff --git a/codex-rs/tui/src/transcript_view/follow_control.rs b/codex-rs/tui/src/transcript_view/follow_control.rsindex ef88d95c12..32256d3a88 100644--- a/codex-rs/tui/src/transcript_view/follow_control.rs+++ b/codex-rs/tui/src/transcript_view/follow_control.rs@@ -1,4 +1,5 @@//! Return-to-latest affordance in the owned transcript's existing composer gap.+//! The control is hidden whenever the current final transcript row is visible.//! Rendering owns the hit rectangle; hidden controls never intercept pointer input.use super::*;@@ -20,7 +21,8 @@ impl TranscriptView {pub(crate) fn render_follow_control(&mut self, area: Option<Rect>, buf: &mut Buffer) {let area = area.filter(|area| {!area.is_empty()- && self.can_return_to_latest()+ && !self.area.is_empty()+ && !self.tail_visible&& self.highlight.is_none()&& self.selection.is_none()&& !self.is_search_active()diff --git a/codex-rs/tui/src/transcript_view/follow_control_tests.rs b/codex-rs/tui/src/transcript_view/follow_control_tests.rsindex 93dcb4b153..2905c33878 100644--- a/codex-rs/tui/src/transcript_view/follow_control_tests.rs+++ b/codex-rs/tui/src/transcript_view/follow_control_tests.rs@@ -2,6 +2,7 @@use super::*;use crate::history_cell::PlainHistoryCell;+use crossterm::event::KeyCode;use crossterm::event::KeyModifiers;use pretty_assertions::assert_eq;@@ -101,6 +102,112 @@ fn no_op_scroll_keeps_following_and_real_scroll_pauses() {assert!(view.is_following());}+#[test]+fn empty_viewport_does_not_show_back_to_bottom() {+ let cells = vec![cell("one")];+ let mut view = TranscriptView::default();+ let gap = Rect::new(+ /*x*/ 0, /*y*/ 0, /*width*/ 40, /*height*/ 1,+ );+ let mut buffer = Buffer::empty(gap);+ view.render(Rect { height: 0, ..gap }, &mut buffer, &cells);+ view.render_follow_control(Some(gap), &mut buffer);++ assert!(view.is_following());+ assert!(view.follow_control.area.is_none());+ assert_eq!(buffer, Buffer::empty(gap));+ insta::assert_snapshot!(crate::transcript_view::tests::text(&buffer), @"");+}++#[test]+fn copying_selection_at_bottom_does_not_show_back_to_bottom() {+ let cells = vec![cell("one\ntwo\nthree\nfour\nneedle")];+ let mut view = TranscriptView::default();+ let before = paint(&mut view, &cells, /*width*/ 40);+ assert!(view.tail_visible);+ assert!(view.follow_control.area.is_none());++ view.begin_selection(&cells, /*column*/ 0, /*row*/ 2, /*clicks*/ 2);+ view.end_drag();+ let selected = view.selected_text(&cells).expect("selected word");+ view.copy_selected_text_with(&cells, &selected, |text| {+ assert_eq!(text, "needle");+ Ok(crate::clipboard_copy::CopyStatus::Confirmed)+ })+ .expect("successful copy");++ let after = paint(&mut view, &cells, /*width*/ 40);+ assert!(view.selected_text(&cells).is_none());+ assert!(!view.is_following());+ assert!(view.tail_visible);+ assert!(view.follow_control.area.is_none());+ assert_eq!(after, before);+ insta::assert_snapshot!(crate::transcript_view::tests::text(&after), @"+ three+ four+ needle+ ");+}++#[test]+fn closing_find_at_bottom_does_not_show_back_to_bottom() {+ let cells = vec![cell("one\ntwo\nthree\nfour\nneedle")];+ let mut view = TranscriptView::default();+ let before = paint(&mut view, &cells, /*width*/ 40);+ view.begin_selection(&cells, /*column*/ 0, /*row*/ 2, /*clicks*/ 2);+ view.end_drag();+ view.begin_search();+ view.paste_search("needle");+ assert!(!view.advance_search(&cells));+ paint(&mut view, &cells, /*width*/ 40);++ view.handle_key(KeyCode::Esc.into(), &cells);+ let after = paint(&mut view, &cells, /*width*/ 40);+ assert!(!view.is_search_active());+ assert!(!view.is_following());+ assert!(view.tail_visible);+ assert!(view.follow_control.area.is_none());+ assert_eq!(after, before);+}++#[test]+fn enlarging_paused_view_hides_back_to_bottom_when_tail_fits() {+ let cells = vec![cell("one\ntwo\nthree\nfour\nfive")];+ let mut view = TranscriptView::default();+ paint(&mut view, &cells, /*width*/ 40);+ view.scroll(&cells, /*rows*/ -2);+ paint(&mut view, &cells, /*width*/ 40);+ assert!(view.follow_control.area.is_some());++ let area = Rect::new(+ /*x*/ 0, /*y*/ 0, /*width*/ 40, /*height*/ 6,+ );+ let mut buffer = Buffer::empty(area);+ view.render(+ Rect::new(+ /*x*/ 0, /*y*/ 0, /*width*/ 40, /*height*/ 5,+ ),+ &mut buffer,+ &cells,+ );+ view.render_follow_control(+ Some(Rect::new(+ /*x*/ 0, /*y*/ 5, /*width*/ 40, /*height*/ 1,+ )),+ &mut buffer,+ );+ assert!(!view.is_following());+ assert!(view.tail_visible);+ assert!(view.follow_control.area.is_none());+ insta::assert_snapshot!(crate::transcript_view::tests::text(&buffer), @"+ one+ two+ three+ four+ five+ ");+}+#[test]fn copying_live_selection_retains_the_displayed_revision() {let mut view = TranscriptView::default();@@ -120,9 +227,17 @@ fn copying_live_selection_retains_the_displayed_revision() {.unwrap();let buffer = paint(&mut view, &cells, /*width*/ 40);assert!(!view.is_following());+ assert!(!view.tail_visible);+ assert!(view.follow_control.area.is_some());assert!(format!("{buffer:?}").contains("original live text"));+ assert!(+ crate::transcript_view::tests::text(&buffer).contains("New activity · ↓ Back to bottom")+ );view.jump_to_latest();- assert!(format!("{:?}", paint(&mut view, &cells, /*width*/ 40)).contains("changed live text"));+ let buffer = paint(&mut view, &cells, /*width*/ 40);+ assert!(format!("{buffer:?}").contains("changed live text"));+ assert!(view.tail_visible);+ assert!(view.follow_control.area.is_none());}#[test]