Allow inline patch review during approval prompts (#58281)

## Why

Collapsed patch details should remain accessible while an approval prompt is open, and reviewing them should not leave the transcript stuck behind new output after approval.

## What changed

Allow clicking transcript disclosure controls while a modal prompt is open. When expanding details during patch approval interrupts following the latest output, resume following once that approval ends or advances to another patch. Preserve manual scrolling and text selection instead of automatically jumping to the latest output.

## Testing

Extend patch approval coverage with an inline expansion snapshot and checks for queued approvals and subsequent output. Add a regression test that preserves manual scroll position when approval ends.

GitOrigin-RevId: 249aa6bb2a84364a8cb111454fa5b6a3dce218b3
This commit is contained in:
Eric Traut
2026-10-30 08:03:51 +00:00
committed by copyberry
parent eab2603712
commit f752c97f7d
14 changed files with 214 additions and 25 deletions
@@ -8,6 +8,7 @@ use crate::bottom_pane::TranscriptFooter;
use crate::key_hint::KeyBindingListExt;
use crate::keymap::ListAction;
use crate::keymap::RuntimeKeymap;
use codex_protocol::ThreadId;
use crossterm::event::KeyEvent;
use ratatui::style::Modifier;
use ratatui::style::Style;
@@ -17,6 +18,7 @@ use super::*;
pub(super) struct Disclosure {
pub(super) expanded: HashSet<String>,
pub(super) focused: Option<Vec<String>>,
pub(super) resume_after_approval: Option<(ThreadId, String)>,
pub(super) live_ids: Vec<String>,
pub(super) keymap: RuntimeKeymap,
}
@@ -26,6 +28,7 @@ impl Default for Disclosure {
Self {
expanded: HashSet::new(),
focused: None,
resume_after_approval: None,
live_ids: Vec::new(),
keymap: RuntimeKeymap::defaults(),
}
@@ -39,6 +42,14 @@ impl Disclosure {
}
impl TranscriptView {
pub(crate) fn sync_patch_approval(&mut self, current: Option<(ThreadId, &str)>) {
if let Some((thread_id, id)) = &self.disclosure.resume_after_approval
&& current != Some((*thread_id, id.as_str()))
{
self.jump_to_latest();
}
}
pub(crate) fn is_activity_focused(&self) -> bool {
self.disclosure.focused.is_some() && !self.detailed && self.mode == HistoryRenderMode::Rich
}
@@ -435,6 +435,50 @@ impl HistoryCell for ActivityCell {
}
}
#[test]
fn patch_disclosure_preserves_manual_scrolling() {
let cells: Vec<Arc<dyn HistoryCell>> = vec![
Arc::new(PlainHistoryCell::new(vec!["older output".into(); 20])),
Arc::new(ActivityCell::default()),
Arc::new(PlainHistoryCell::new(vec!["tail".into()])),
];
let area = Rect::new(
/*x*/ 0, /*y*/ 0, /*width*/ 32, /*height*/ 10,
);
for scroll_before_click in [false, true] {
let mut view = TranscriptView::default();
let mut buf = Buffer::empty(area);
view.render(area, &mut buf, &cells);
if scroll_before_click {
view.scroll(&cells, /*rows*/ -1);
view.render(area, &mut buf, &cells);
}
let (column, row) = crate::transcript_view::tests::text(&buf)
.lines()
.enumerate()
.find_map(|(row, line)| line.find("+ Show details").map(|column| (column, row)))
.expect("activity disclosure");
view.handle_selection_mouse(
MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: column as u16,
row: row as u16,
modifiers: KeyModifiers::NONE,
},
&cells,
Some((codex_protocol::ThreadId::new(), "patch")),
);
assert!(view.is_activity_focused());
if !scroll_before_click {
view.scroll(&cells, /*rows*/ -1);
}
let position = view.position;
view.sync_patch_approval(/*current*/ None);
assert_eq!(view.position, position);
assert!(!view.is_following());
}
}
#[test]
fn activity_focus_keeps_controls_without_passive_hints() {
let mut cells: Vec<Arc<dyn HistoryCell>> = Vec::new();
+19 -8
View File
@@ -7,6 +7,7 @@
//! Wheel input accumulates fractional rows and discards the remainder when direction reverses.
use crate::key_hint::KeyBindingListExt;
use codex_protocol::ThreadId;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyEventKind;
@@ -29,9 +30,9 @@ pub(crate) enum ViewAction {
}
#[derive(Clone, Copy, PartialEq, Eq)]
enum MouseMode {
enum MouseMode<'a> {
Interactive,
Selection,
Selection(Option<(ThreadId, &'a str)>),
}
/// Transcript jumps shared with input routing so legacy terminals preserve their Alt modifier.
@@ -251,16 +252,17 @@ impl TranscriptView {
cells: &[Arc<dyn HistoryCell>],
) -> Option<ViewAction> {
if self.select_mode.is_some() {
return self.handle_selection_mouse(event, cells);
return self.handle_selection_mouse(event, cells, /*patch_approval*/ None);
}
self.handle_mouse_with_mode(event, cells, MouseMode::Interactive)
}
/// Handles selection and scrolling without activating transcript content.
/// Modals allow transcript disclosure, while select mode keeps clicks for text selection.
pub(crate) fn handle_selection_mouse(
&mut self,
event: MouseEvent,
cells: &[Arc<dyn HistoryCell>],
patch_approval: Option<(ThreadId, &str)>,
) -> Option<ViewAction> {
let endpoint_changed = matches!(
event.kind,
@@ -272,12 +274,16 @@ impl TranscriptView {
.selection
.as_ref()
.map(|selection| (selection.start, selection.end, selection.unit()));
let action = self.handle_mouse_with_mode(event, cells, MouseMode::Selection);
let action =
self.handle_mouse_with_mode(event, cells, MouseMode::Selection(patch_approval));
let after = self
.selection
.as_ref()
.map(|selection| (selection.start, selection.end, selection.unit()));
if endpoint_changed && before != after {
if self.has_selection_range() {
self.disclosure.resume_after_approval = None;
}
self.adopt_select_mouse_range();
}
action
@@ -287,7 +293,7 @@ impl TranscriptView {
&mut self,
event: MouseEvent,
cells: &[Arc<dyn HistoryCell>],
mode: MouseMode,
mode: MouseMode<'_>,
) -> Option<ViewAction> {
if mode == MouseMode::Interactive
&& let Some(action) = self.handle_follow_control_mouse(event)
@@ -498,12 +504,17 @@ impl TranscriptView {
&mut self,
event: MouseEvent,
cells: &[Arc<dyn HistoryCell>],
mode: MouseMode,
mode: MouseMode<'_>,
) -> Option<ViewAction> {
if mode == MouseMode::Interactive
let was_following = self.is_following();
if !self.is_select_mode()
&& event.modifiers.is_empty()
&& self.toggle_disclosure_at(cells, event.column, event.row)
{
// Keep the patch anchored for inspection, then follow again when the prompt closes.
if was_following && let MouseMode::Selection(Some((thread_id, id))) = mode {
self.disclosure.resume_after_approval = Some((thread_id, id.to_owned()));
}
return Some(ViewAction::Changed);
}
self.disclosure.focused = None;
@@ -319,7 +319,7 @@ fn selection_mouse_does_not_open_links() {
)
};
assert!(matches!(
view.handle_selection_mouse(down, &cells),
view.handle_selection_mouse(down, &cells, /*patch_approval*/ None),
Some(ViewAction::Changed)
));
let area = view.area;
@@ -331,6 +331,7 @@ fn selection_mouse_does_not_open_links() {
..down
},
&cells,
/*patch_approval*/ None,
),
Some(ViewAction::Changed)
));