mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
Cache TUI flex heights across frame passes (#34348)
## Why Sizing, rendering, and cursor placement can query the same chat widget layout multiple times in one frame, repeatedly measuring active transcript cells. ## What changed - Build one chat widget renderable tree per frame and reuse it for sizing, rendering, and cursor placement. - Cache each flex child's desired height by width for the lifetime of that tree. - Reuse the bottom pane's renderable directly instead of forwarding each renderable operation through a wrapper. ## Testing - Verify flex layouts measure a child once across frame passes and remeasure it when the width changes. - Verify a chat widget frame measures its active transcript cell once. GitOrigin-RevId: 5ad1a6711f4011c699b5d002b13dc3319cb4db8e
This commit is contained in:
1 parent
ada5a79ddf
commit
eceb3eeaf3
7 files changed
+141
-90
No files matched your search
+24
-12
@@ -1364,18 +1364,30 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
}
|
||||
|
||||
fn render_chat_widget_frame(&mut self, tui: &mut tui::Tui) -> Result<Rect> {
|
||||
let desired_height = self.chat_widget.desired_height(tui.terminal.size()?.width);
|
||||
let mut rendered_area = Rect::default();
|
||||
tui.draw_with_resize_reflow(desired_height, |frame| {
|
||||
let area = frame.area();
|
||||
rendered_area = area;
|
||||
self.chat_widget.render(area, frame.buffer);
|
||||
if let Some((x, y)) = self.chat_widget.cursor_pos(area) {
|
||||
frame.set_cursor_style(self.chat_widget.cursor_style(area));
|
||||
frame.set_cursor_position((x, y));
|
||||
}
|
||||
})?;
|
||||
Ok(rendered_area)
|
||||
let width = tui.terminal.size()?.width;
|
||||
self.with_chat_widget_frame(width, |desired_height, chat_widget| {
|
||||
let mut rendered_area = Rect::default();
|
||||
tui.draw_with_resize_reflow(desired_height, |frame| {
|
||||
let area = frame.area();
|
||||
rendered_area = area;
|
||||
chat_widget.render(area, frame.buffer);
|
||||
self.chat_widget.note_rendered_width(area.width);
|
||||
if let Some((x, y)) = chat_widget.cursor_pos(area) {
|
||||
frame.set_cursor_style(chat_widget.cursor_style(area));
|
||||
frame.set_cursor_position((x, y));
|
||||
}
|
||||
})?;
|
||||
Ok(rendered_area)
|
||||
})
|
||||
}
|
||||
|
||||
fn with_chat_widget_frame<T>(
|
||||
&self,
|
||||
width: u16,
|
||||
render: impl FnOnce(u16, &dyn Renderable) -> T,
|
||||
) -> T {
|
||||
let chat_widget = self.chat_widget.as_renderable();
|
||||
render(chat_widget.desired_height(width), &chat_widget)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user