From 506a328dab110591d3c1449a15217596e7e9cd61 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 22 Sep 2026 23:00:40 +0000 Subject: [PATCH] Restore composer hints after clearing selection at the transcript bottom (#47384) ## Why Selecting text can pause following while the final transcript row remains visible. Clearing that selection could leave an unnecessary `esc latest` hint in place of the composer hints. ## What changed Only show the return-to-latest footer for paused navigation when the transcript tail is out of view. At the bottom, show selection shortcuts without the earlier-history status, then restore composer hints when the selection is cleared, even if following remains paused. Preserve loading and retry hints. ## Testing Add regression coverage for selection, clicking away, and scrolling at the bottom with partial and complete history, plus selection above the bottom. Verify retry hints with selected text and update activity expectations and the composer-gap snapshot. GitOrigin-RevId: aeb2109244d6c3214c945abb51cf469087d03074 --- ..._tests__owned_transcript_composer_gap.snap | 3 +- .../tui/src/transcript_view/activity_tests.rs | 8 +- codex-rs/tui/src/transcript_view/footer.rs | 30 +++-- .../tui/src/transcript_view/footer_tests.rs | 110 ++++++++++++++++++ 4 files changed, 130 insertions(+), 21 deletions(-) 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.snap index 739480451e..b2417f42ea 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: 227 +assertion_line: 350 expression: "snapshots.join(\"\\n\\n\")" --- Latest @@ -64,4 +64,3 @@ Detailed › preserved draft gpt-test default · /tmp/project - esc latest diff --git a/codex-rs/tui/src/transcript_view/activity_tests.rs b/codex-rs/tui/src/transcript_view/activity_tests.rs index d88e3e8d9a..dceb3ac7df 100644 --- a/codex-rs/tui/src/transcript_view/activity_tests.rs +++ b/codex-rs/tui/src/transcript_view/activity_tests.rs @@ -33,13 +33,7 @@ fn visible_updates_and_empty_tail_cells_do_not_report_activity() { assert!(view.unseen_activity); render(&mut view, &cells, /*height*/ 8); assert!(!view.unseen_activity); - assert_eq!( - view.footer(/*width*/ 80, MotionMode::Reduced) - .unwrap() - .text - .to_string(), - "esc latest" - ); + assert!(view.footer(/*width*/ 80, MotionMode::Reduced).is_none()); } #[test] diff --git a/codex-rs/tui/src/transcript_view/footer.rs b/codex-rs/tui/src/transcript_view/footer.rs index a8437b5d00..9de9090061 100644 --- a/codex-rs/tui/src/transcript_view/footer.rs +++ b/codex-rs/tui/src/transcript_view/footer.rs @@ -41,18 +41,23 @@ impl TranscriptView { is_interactive: true, }); } + let pending = self.is_loading_history() || self.history == TranscriptHistoryState::Failed; if has_selected_text { return Some(TranscriptFooter { - text: first_fitting_line( - [ - self.status_line_with_navigation( - "ctrl+c copy · enter copy & follow · esc clear", - motion, - ), - selection_hint(width), - ], - width, - ) + text: if self.tail_visible && !pending { + selection_hint(width) + } else { + first_fitting_line( + [ + self.status_line_with_navigation( + "ctrl+c copy · enter copy & follow · esc clear", + motion, + ), + selection_hint(width), + ], + width, + ) + } .into(), cursor_column: None, is_interactive: true, @@ -61,8 +66,9 @@ impl TranscriptView { if self.is_activity_focused() { return self.disclosure_footer(width); } - let pending = self.is_loading_history() || self.history == TranscriptHistoryState::Failed; - let can_return = self.selection.is_none() && self.can_return_to_latest(); + // Selection can pause following without hiding the current final row. + let can_return = + self.selection.is_none() && self.can_return_to_latest() && !self.tail_visible; (pending || self.unseen_activity || can_return).then(|| { let navigation = if self.can_return_to_latest() { latest_navigation diff --git a/codex-rs/tui/src/transcript_view/footer_tests.rs b/codex-rs/tui/src/transcript_view/footer_tests.rs index 52a0139352..779acaf369 100644 --- a/codex-rs/tui/src/transcript_view/footer_tests.rs +++ b/codex-rs/tui/src/transcript_view/footer_tests.rs @@ -13,6 +13,106 @@ use pretty_assertions::assert_eq; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; +#[test] +fn selection_at_bottom_restores_footer_without_resuming_following() { + let cells: Vec> = vec![Arc::new(PlainHistoryCell::new(vec![ + "one".into(), + "two".into(), + "three".into(), + "four".into(), + "needle final".into(), + ]))]; + let mut observations = Vec::new(); + for history in [ + TranscriptHistoryState::Partial, + TranscriptHistoryState::Complete, + ] { + let mut view = TranscriptView { + history, + ..TranscriptView::default() + }; + let initial = render(&mut view, &cells); + assert!(view.tail_visible); + assert!(view.is_following()); + assert!(view.footer(/*width*/ 120, MotionMode::Reduced).is_none()); + + for (label, events) in [ + ( + "selected at bottom", + vec![ + (MouseEventKind::Down(MouseButton::Left), 0, 2), + (MouseEventKind::Drag(MouseButton::Left), 6, 2), + (MouseEventKind::Up(MouseButton::Left), 6, 2), + ], + ), + ( + "clicked away", + vec![ + (MouseEventKind::Down(MouseButton::Left), 0, 1), + (MouseEventKind::Up(MouseButton::Left), 0, 1), + ], + ), + ( + "scrolled down at bottom", + vec![(MouseEventKind::ScrollDown, 0, 1)], + ), + ] { + let mut buffer = initial.clone(); + for (kind, column, row) in events { + view.handle_mouse( + MouseEvent { + kind, + column, + row, + modifiers: KeyModifiers::NONE, + }, + &cells, + ); + buffer = render(&mut view, &cells); + } + assert!(view.tail_visible); + assert_eq!( + crate::transcript_view::tests::text(&buffer), + crate::transcript_view::tests::text(&initial), + ); + let selected = label == "selected at bottom"; + assert_eq!( + view.selected_text(&cells).as_deref(), + selected.then_some("needle"), + ); + assert_eq!(view.is_following(), label == "scrolled down at bottom"); + let footer = view.footer(/*width*/ 120, MotionMode::Reduced); + let hint = footer.map_or_else( + || "".to_owned(), + |footer| footer.text.to_string(), + ); + observations.push(format!("{history:?}, {label}: {hint}")); + } + view.scroll(&cells, /*rows*/ -1); + render(&mut view, &cells); + view.begin_selection(&cells, /*column*/ 0, /*row*/ 0, /*clicks*/ 3); + view.end_drag(); + render(&mut view, &cells); + assert!(!view.tail_visible); + assert_eq!(view.selected_text(&cells).as_deref(), Some("two\n")); + let footer = view.footer(/*width*/ 120, MotionMode::Reduced).unwrap(); + observations.push(format!( + "{history:?}, selected above bottom: {}", + footer.text + )); + } + insta::assert_snapshot!(observations.join("\n"), @" + Partial, selected at bottom: ctrl+c copy · enter copy & follow · esc clear + Partial, clicked away: + Partial, scrolled down at bottom: + Partial, selected above bottom: Earlier messages available. ctrl+c copy · enter copy & follow · esc clear + Complete, selected at bottom: ctrl+c copy · enter copy & follow · esc clear + Complete, clicked away: + Complete, scrolled down at bottom: + Complete, selected above bottom: ctrl+c copy · enter copy & follow · esc clear + "); +} + fn render(view: &mut TranscriptView, cells: &[Arc]) -> Buffer { let area = Rect::new( /*x*/ 0, /*y*/ 0, /*width*/ 32, /*height*/ 3, @@ -115,6 +215,16 @@ fn loading_preserves_selected_content_and_copy_action() { Some("selected words".to_string()) ); view.history = TranscriptHistoryState::Failed; + assert_eq!( + view.footer(/*width*/ 120, MotionMode::Reduced) + .unwrap() + .text + .to_string(), + format!( + "ctrl+c copy · enter copy & follow · esc clear · Retry: {}", + JumpTarget::Beginning.hint_label(), + ), + ); insta::assert_snapshot!(view.footer(/*width*/ 38, MotionMode::Reduced).unwrap().text.to_string(), @"enter copy & follow · esc clear"); }