mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Group consecutive transcript prompts into one background block (#56280)
## Why Consecutive user prompts in the rich transcript have extra blank spacing that breaks up their shared background. ## What changed - Join adjacent visible user prompts into one background block, skipping hidden entries when determining adjacency. - Keep prompts separated when intervening content becomes visible through detailed mode or search, and restore grouping when it is hidden again. - Preserve selectable source offsets and joined spacing when text is rewrapped, and reuse cached layouts when checking adjacency. ## Testing Add regression tests for prompt grouping, layout cache reuse, source offsets across rewrapping, detailed reasoning, and search-driven visibility. Update transcript snapshots to reflect the tighter spacing. GitOrigin-RevId: faca8001244b0ac883d9d670864c8f7856ac2bad
This commit is contained in:
committed by
copyberry
parent
d124fe9de1
commit
35e2102808
@@ -1,6 +1,7 @@
|
||||
//! Viewport behavior and cache lifetime across scrolling, selection, and redraws.
|
||||
|
||||
use super::*;
|
||||
use crate::history_cell::new_user_prompt;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
@@ -38,6 +39,15 @@ pub(super) fn cell(text: impl Into<String>) -> Arc<dyn HistoryCell> {
|
||||
})
|
||||
}
|
||||
|
||||
fn prompt(text: impl Into<String>) -> Arc<dyn HistoryCell> {
|
||||
Arc::new(new_user_prompt(
|
||||
text.into(),
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
))
|
||||
}
|
||||
|
||||
pub(super) fn render(
|
||||
view: &mut TranscriptView,
|
||||
cells: &[Arc<dyn HistoryCell>],
|
||||
@@ -63,6 +73,115 @@ pub(super) fn text(buffer: &Buffer) -> String {
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn consecutive_user_prompts_share_one_background_block() {
|
||||
use crate::history_cell::AgentMessageCell;
|
||||
use crate::history_cell::new_spoken_user_prompt;
|
||||
use codex_protocol::user_input::TextElement;
|
||||
|
||||
let cells: Vec<Arc<dyn HistoryCell>> = vec![
|
||||
prompt("First steering message"),
|
||||
prompt("Second steering message"),
|
||||
Arc::new(AgentMessageCell::new(
|
||||
vec!["Assistant response".into()],
|
||||
/*is_first_line*/ true,
|
||||
)),
|
||||
Arc::new(new_spoken_user_prompt(String::new())),
|
||||
Arc::new(new_user_prompt(
|
||||
" ".into(),
|
||||
vec![TextElement::new((0..3).into(), Some(" ".into()))],
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
)),
|
||||
prompt("Later user message"),
|
||||
];
|
||||
crate::terminal_palette::with_test_default_colors(
|
||||
crate::terminal_probe::DefaultColors {
|
||||
fg: (235, 235, 235),
|
||||
bg: (18, 20, 30),
|
||||
},
|
||||
|| {
|
||||
let mut view = TranscriptView::default();
|
||||
let buffer = render(&mut view, &cells, /*width*/ 32, /*height*/ 12);
|
||||
insta::assert_snapshot!(
|
||||
"consecutive_user_prompts_share_one_background_block",
|
||||
format!("{buffer:?}")
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prompt_adjacency_uses_cached_retained_presentations() {
|
||||
let renders = Arc::new(AtomicUsize::new(0));
|
||||
let cells: Vec<Arc<dyn HistoryCell>> = vec![
|
||||
Arc::new(TestCell {
|
||||
text: "response".into(),
|
||||
renders: Arc::clone(&renders),
|
||||
}),
|
||||
prompt("steering"),
|
||||
];
|
||||
let mut view = TranscriptView::default();
|
||||
|
||||
view.current_layout(&cells, /*index*/ 1);
|
||||
view.current_layout(&cells, /*index*/ 1);
|
||||
|
||||
assert_eq!(renders.load(Ordering::Relaxed), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn joined_prompt_preserves_source_offsets_across_rewrap() {
|
||||
let cells = vec![prompt("older"), prompt("one\n\ntwo")];
|
||||
let mut view = TranscriptView::default();
|
||||
let unjoined = [Arc::clone(&cells[1])];
|
||||
let source = view
|
||||
.current_layout(&unjoined, /*index*/ 0)
|
||||
.unwrap()
|
||||
.text()
|
||||
.to_owned();
|
||||
let joined = view.current_layout(&cells, /*index*/ 1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
(joined.text(), joined.rewrap(/*width*/ 8).text()),
|
||||
(source.as_str(), source.as_str())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detailed_only_reasoning_separates_user_prompts() {
|
||||
use crate::history_cell::ReasoningSummaryCell;
|
||||
use std::path::Path;
|
||||
|
||||
let cells: Vec<Arc<dyn HistoryCell>> = vec![
|
||||
prompt("first"),
|
||||
Arc::new(ReasoningSummaryCell::new(
|
||||
"Reasoning".into(),
|
||||
"visible detail".into(),
|
||||
Path::new("."),
|
||||
/*transcript_only*/ true,
|
||||
)),
|
||||
prompt("second"),
|
||||
];
|
||||
let mut detailed = TranscriptView {
|
||||
detailed: true,
|
||||
..TranscriptView::default()
|
||||
};
|
||||
assert!(
|
||||
detailed
|
||||
.current_layout(&cells, /*index*/ 2)
|
||||
.unwrap()
|
||||
.separated
|
||||
);
|
||||
|
||||
let mut compact = TranscriptView::default();
|
||||
assert!(
|
||||
!compact
|
||||
.entry_layout(&cells, /*index*/ 2, /*full_content*/ true)
|
||||
.unwrap()
|
||||
.separated
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_keys_follow_pager_scroll_bindings() {
|
||||
let cells = [cell(
|
||||
|
||||
Reference in New Issue
Block a user