mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Fix transcript viewer restoration and half-page scrolling (#43889)
## Why Repeated alternate-screen entry can overwrite the saved inline viewport, and half-page scrolling can use a different height from the rendered transcript. ## What changed - Make alternate-screen entry idempotent to preserve the inline viewport for restoration. - Defer transcript reflow after raw output mode changes while an overlay is open, preserving queued history until the overlay closes. - Use the last rendered content height for half-page scrolling, matching full-page scrolling. ## Testing Add regression coverage for restoring the inline viewport and draft after closing the transcript with pending history and a raw output mode change, plus half-page scrolling when the rendered height differs from the terminal viewport. GitOrigin-RevId: 30847df4b6383db26791ebda20470c9b169f9680
This commit is contained in:
1 parent
5a65fd87d8
commit
095da4b7e8
7 files changed
+150
-19
No files matched your search
+9
@@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tui/src/app/tests/transcript_composer.rs
|
||||
expression: "buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal))"
|
||||
---
|
||||
|
||||
|
||||
› EDGE-DRAFT-MUST-SURVIVE
|
||||
|
||||
gpt-5.6-sol default · /tmp/project
|
||||
@@ -1,13 +1,29 @@
|
||||
//! Regression coverage for transcript viewer input and prompt selection.
|
||||
//! Regression coverage for transcript viewer input, prompt selection, and restoration.
|
||||
//!
|
||||
//! The default-off feature must leave the existing viewer and its draft intact.
|
||||
|
||||
use super::*;
|
||||
use crate::test_support::test_path_display;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn buffer_text(buffer: &ratatui::buffer::Buffer) -> String {
|
||||
buffer
|
||||
.content()
|
||||
.chunks(usize::from(buffer.area.width))
|
||||
.map(|row| {
|
||||
row.iter()
|
||||
.map(ratatui::buffer::Cell::symbol)
|
||||
.collect::<String>()
|
||||
.trim_end()
|
||||
.to_string()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
async fn press_key(
|
||||
app: &mut App,
|
||||
tui: &mut crate::tui::Tui,
|
||||
@@ -73,19 +89,7 @@ async fn transcript_flag_off_preserves_viewer_and_backtracking() -> Result<()> {
|
||||
panic!("viewer closed")
|
||||
};
|
||||
overlay.render(area, &mut buffer);
|
||||
let text = buffer
|
||||
.content()
|
||||
.chunks(usize::from(area.width))
|
||||
.map(|row| {
|
||||
row.iter()
|
||||
.map(ratatui::buffer::Cell::symbol)
|
||||
.collect::<String>()
|
||||
.trim_end()
|
||||
.to_string()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!("transcript_flag_off_viewer", text);
|
||||
insta::assert_snapshot!("transcript_flag_off_viewer", buffer_text(&buffer));
|
||||
for (key, selected) in [
|
||||
(KeyCode::Esc, 1),
|
||||
(KeyCode::Esc, 0),
|
||||
@@ -108,3 +112,57 @@ async fn transcript_flag_off_preserves_viewer_and_backtracking() -> Result<()> {
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn assert_transcript_close_repaints_inline_draft(mut app: App) -> Result<()> {
|
||||
let mut app_server = start_config_write_test_app_server(&app).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
app.chat_widget.insert_str("EDGE-DRAFT-MUST-SURVIVE");
|
||||
app.handle_tui_event(&mut tui, &mut app_server, TuiEvent::Draw)
|
||||
.await?;
|
||||
let inline_viewport = tui.terminal.viewport_area;
|
||||
app.open_transcript_overlay(&mut tui);
|
||||
tui.enter_alt_screen()?;
|
||||
app.insert_history_cell(
|
||||
&mut tui,
|
||||
Box::new(PlainHistoryCell::new(vec!["arrived in transcript".into()])),
|
||||
);
|
||||
let deferred_history = app.deferred_history_lines.clone();
|
||||
assert!(!deferred_history.is_empty());
|
||||
app.apply_raw_output_mode(&mut tui, /*enabled*/ true, /*notify*/ false);
|
||||
app.handle_tui_event(&mut tui, &mut app_server, TuiEvent::Draw)
|
||||
.await?;
|
||||
assert_eq!(app.deferred_history_lines, deferred_history);
|
||||
assert!(app.transcript_reflow.has_pending_reflow());
|
||||
|
||||
app.handle_tui_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
TuiEvent::Key(KeyEvent::new(KeyCode::Char('t'), KeyModifiers::CONTROL)),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(tui.terminal.viewport_area, inline_viewport);
|
||||
app.handle_tui_event(&mut tui, &mut app_server, TuiEvent::Draw)
|
||||
.await?;
|
||||
assert!(!app.transcript_reflow.has_pending_reflow());
|
||||
assert_eq!(
|
||||
app.last_rendered_history_tail
|
||||
.as_ref()
|
||||
.expect("inline history reflowed")
|
||||
.lines,
|
||||
deferred_history
|
||||
);
|
||||
|
||||
insta::assert_snapshot!(
|
||||
"transcript_close_restores_inline_draft",
|
||||
buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(
|
||||
&tui.terminal
|
||||
))
|
||||
.replace(&test_path_display("/tmp/project"), "/tmp/project")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn transcript_viewer_close_repaints_preserved_inline_draft() -> Result<()> {
|
||||
assert_transcript_close_repaints_inline_draft(make_test_app().await).await
|
||||
}
|
||||
Reference in new issue
Block a user