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
@@ -226,6 +226,10 @@ impl App {
|
|||||||
} else {
|
} else {
|
||||||
self.chat_widget.set_raw_output_mode(enabled);
|
self.chat_widget.set_raw_output_mode(enabled);
|
||||||
}
|
}
|
||||||
|
if self.overlay.is_some() {
|
||||||
|
self.schedule_immediate_resize_reflow(tui);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let terminal_width = tui.terminal.last_known_screen_size.into();
|
let terminal_width = tui.terminal.last_known_screen_size.into();
|
||||||
if let Err(err) = self.reflow_transcript_now(tui, terminal_width) {
|
if let Err(err) = self.reflow_transcript_now(tui, terminal_width) {
|
||||||
tracing::warn!(error = %err, "failed to reflow transcript after raw output mode toggle");
|
tracing::warn!(error = %err, "failed to reflow transcript after raw output mode toggle");
|
||||||
|
|||||||
+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.
|
//! The default-off feature must leave the existing viewer and its draft intact.
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::test_support::test_path_display;
|
||||||
use crossterm::event::KeyCode;
|
use crossterm::event::KeyCode;
|
||||||
use crossterm::event::KeyEvent;
|
use crossterm::event::KeyEvent;
|
||||||
use crossterm::event::KeyModifiers;
|
use crossterm::event::KeyModifiers;
|
||||||
use pretty_assertions::assert_eq;
|
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(
|
async fn press_key(
|
||||||
app: &mut App,
|
app: &mut App,
|
||||||
tui: &mut crate::tui::Tui,
|
tui: &mut crate::tui::Tui,
|
||||||
@@ -73,19 +89,7 @@ async fn transcript_flag_off_preserves_viewer_and_backtracking() -> Result<()> {
|
|||||||
panic!("viewer closed")
|
panic!("viewer closed")
|
||||||
};
|
};
|
||||||
overlay.render(area, &mut buffer);
|
overlay.render(area, &mut buffer);
|
||||||
let text = buffer
|
insta::assert_snapshot!("transcript_flag_off_viewer", buffer_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);
|
|
||||||
for (key, selected) in [
|
for (key, selected) in [
|
||||||
(KeyCode::Esc, 1),
|
(KeyCode::Esc, 1),
|
||||||
(KeyCode::Esc, 0),
|
(KeyCode::Esc, 0),
|
||||||
@@ -108,3 +112,57 @@ async fn transcript_flag_off_preserves_viewer_and_backtracking() -> Result<()> {
|
|||||||
);
|
);
|
||||||
Ok(())
|
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
|
||||||
|
}
|
||||||
@@ -50,6 +50,10 @@ use ratatui::widgets::WidgetRef;
|
|||||||
|
|
||||||
mod cursor;
|
mod cursor;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "custom_terminal_test_support.rs"]
|
||||||
|
pub(crate) mod test_support;
|
||||||
|
|
||||||
fn osc8_hyperlink_parts(symbol: &str) -> Option<(&str, &str)> {
|
fn osc8_hyperlink_parts(symbol: &str) -> Option<(&str, &str)> {
|
||||||
let content = symbol.strip_prefix("\x1b]8;;")?;
|
let content = symbol.strip_prefix("\x1b]8;;")?;
|
||||||
let destination_end = content.find('\x07')?;
|
let destination_end = content.find('\x07')?;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
//! Inspect the completed frame without adding test helpers to the terminal implementation.
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use ratatui::backend::Backend;
|
||||||
|
use ratatui::buffer::Buffer;
|
||||||
|
|
||||||
|
use super::Terminal;
|
||||||
|
|
||||||
|
pub(crate) fn last_rendered_buffer<B>(terminal: &Terminal<B>) -> &Buffer
|
||||||
|
where
|
||||||
|
B: Backend<Error = io::Error> + Write,
|
||||||
|
{
|
||||||
|
terminal.previous_buffer()
|
||||||
|
}
|
||||||
@@ -307,13 +307,17 @@ impl PagerView {
|
|||||||
self.scroll_offset = self.scroll_offset.saturating_add(page_height);
|
self.scroll_offset = self.scroll_offset.saturating_add(page_height);
|
||||||
}
|
}
|
||||||
e if self.keymap.half_page_down.is_pressed(e) => {
|
e if self.keymap.half_page_down.is_pressed(e) => {
|
||||||
let area = self.content_area(tui.terminal.viewport_area);
|
let half_page = self
|
||||||
let half_page = (area.height as usize).saturating_add(1) / 2;
|
.page_height(tui.terminal.viewport_area)
|
||||||
|
.saturating_add(1)
|
||||||
|
/ 2;
|
||||||
self.scroll_offset = self.scroll_offset.saturating_add(half_page);
|
self.scroll_offset = self.scroll_offset.saturating_add(half_page);
|
||||||
}
|
}
|
||||||
e if self.keymap.half_page_up.is_pressed(e) => {
|
e if self.keymap.half_page_up.is_pressed(e) => {
|
||||||
let area = self.content_area(tui.terminal.viewport_area);
|
let half_page = self
|
||||||
let half_page = (area.height as usize).saturating_add(1) / 2;
|
.page_height(tui.terminal.viewport_area)
|
||||||
|
.saturating_add(1)
|
||||||
|
/ 2;
|
||||||
self.scroll_offset = self.scroll_offset.saturating_sub(half_page);
|
self.scroll_offset = self.scroll_offset.saturating_sub(half_page);
|
||||||
}
|
}
|
||||||
e if self.keymap.jump_top.is_pressed(e) => {
|
e if self.keymap.jump_top.is_pressed(e) => {
|
||||||
@@ -1052,6 +1056,7 @@ mod tests {
|
|||||||
use crate::history_cell::HistoryCell;
|
use crate::history_cell::HistoryCell;
|
||||||
use crate::history_cell::new_patch_event;
|
use crate::history_cell::new_patch_event;
|
||||||
use codex_protocol::parse_command::ParsedCommand;
|
use codex_protocol::parse_command::ParsedCommand;
|
||||||
|
use crossterm::event::KeyModifiers;
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use ratatui::backend::TestBackend;
|
use ratatui::backend::TestBackend;
|
||||||
use ratatui::text::Text;
|
use ratatui::text::Text;
|
||||||
@@ -1777,6 +1782,41 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn half_page_uses_the_last_rendered_content_height() -> Result<()> {
|
||||||
|
let mut overlay = transcript_overlay(
|
||||||
|
(0..50)
|
||||||
|
.map(|i| {
|
||||||
|
Arc::new(TestCell {
|
||||||
|
lines: vec![Line::from(format!("line-{i:02}"))],
|
||||||
|
}) as Arc<dyn HistoryCell>
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
let transcript_area = Rect::new(
|
||||||
|
/*x*/ 0, /*y*/ 0, /*width*/ 40, /*height*/ 10,
|
||||||
|
);
|
||||||
|
let mut buf = Buffer::empty(transcript_area);
|
||||||
|
overlay.render(transcript_area, &mut buf);
|
||||||
|
let page_height = overlay.view.page_height(transcript_area);
|
||||||
|
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||||
|
tui.terminal.set_viewport_area(Rect::new(
|
||||||
|
/*x*/ 0, /*y*/ 0, /*width*/ 40, /*height*/ 24,
|
||||||
|
));
|
||||||
|
overlay.view.scroll_offset = 10;
|
||||||
|
|
||||||
|
overlay.view.handle_key_event(
|
||||||
|
&mut tui,
|
||||||
|
KeyEvent::new(KeyCode::Char('d'), KeyModifiers::CONTROL),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
overlay.view.scroll_offset,
|
||||||
|
10 + page_height.saturating_add(1) / 2
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn static_overlay_wraps_long_lines() {
|
fn static_overlay_wraps_long_lines() {
|
||||||
let mut overlay = static_overlay(
|
let mut overlay = static_overlay(
|
||||||
|
|||||||
@@ -837,7 +837,7 @@ impl Tui {
|
|||||||
/// Enter alternate screen and expand the viewport to full terminal size, saving the current
|
/// Enter alternate screen and expand the viewport to full terminal size, saving the current
|
||||||
/// inline viewport for restoration when leaving.
|
/// inline viewport for restoration when leaving.
|
||||||
pub fn enter_alt_screen(&mut self) -> Result<()> {
|
pub fn enter_alt_screen(&mut self) -> Result<()> {
|
||||||
if !self.alt_screen_enabled {
|
if !self.alt_screen_enabled || self.is_alt_screen_active() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let _ = execute!(self.terminal.backend_mut(), EnterAlternateScreen);
|
let _ = execute!(self.terminal.backend_mut(), EnterAlternateScreen);
|
||||||
|
|||||||
Reference in new issue
Block a user