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
@@ -307,13 +307,17 @@ impl PagerView {
|
||||
self.scroll_offset = self.scroll_offset.saturating_add(page_height);
|
||||
}
|
||||
e if self.keymap.half_page_down.is_pressed(e) => {
|
||||
let area = self.content_area(tui.terminal.viewport_area);
|
||||
let half_page = (area.height as usize).saturating_add(1) / 2;
|
||||
let half_page = self
|
||||
.page_height(tui.terminal.viewport_area)
|
||||
.saturating_add(1)
|
||||
/ 2;
|
||||
self.scroll_offset = self.scroll_offset.saturating_add(half_page);
|
||||
}
|
||||
e if self.keymap.half_page_up.is_pressed(e) => {
|
||||
let area = self.content_area(tui.terminal.viewport_area);
|
||||
let half_page = (area.height as usize).saturating_add(1) / 2;
|
||||
let half_page = self
|
||||
.page_height(tui.terminal.viewport_area)
|
||||
.saturating_add(1)
|
||||
/ 2;
|
||||
self.scroll_offset = self.scroll_offset.saturating_sub(half_page);
|
||||
}
|
||||
e if self.keymap.jump_top.is_pressed(e) => {
|
||||
@@ -1052,6 +1056,7 @@ mod tests {
|
||||
use crate::history_cell::HistoryCell;
|
||||
use crate::history_cell::new_patch_event;
|
||||
use codex_protocol::parse_command::ParsedCommand;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::TestBackend;
|
||||
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]
|
||||
fn static_overlay_wraps_long_lines() {
|
||||
let mut overlay = static_overlay(
|
||||
|
||||
Reference in new issue
Block a user