Preserve transcript layout caches during backtrack selection (#41940)

## Why

Moving between prompts in backtrack mode rebuilt every transcript renderable and
discarded their cached heights, causing the entire transcript to be laid out
again for each selection change.

## What changed

Rerender only the previously highlighted cell and the newly highlighted cell.
Keep all other renderables, cached heights, and the live tail intact while
continuing to scroll the selected prompt into view.

## Testing

Add regression tests that verify selection changes preserve unrelated height
caches and produce the same viewport and scroll position as a full rebuild,
including with a live tail and terminal width changes.

GitOrigin-RevId: 685a8ce65ecadef20521ce2ded7b516fdf8499c9
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-01 00:12:22 +00:00
1 parent 0e03f88a30
commit c5a3700dd7
2 files changed
+163 -2

No files matched your search

+19 -2
View File
@@ -17,6 +17,10 @@
mod scrolling;
#[cfg(test)]
#[path = "pager_overlay/highlight_tests.rs"]
mod highlight_tests;
use std::io::Result;
use std::sync::Arc;
@@ -798,9 +802,22 @@ impl TranscriptOverlay {
}
pub(crate) fn set_highlight_cell(&mut self, cell: Option<usize>) {
let live_tail = self.take_live_tail_renderable();
let previous = self.highlight_cell;
self.highlight_cell = cell;
self.rebuild_renderables(live_tail);
// Highlighting changes only these cells' styling. Keep the other renderables and their
// cached heights so moving between prompts does not lay out the entire transcript again.
if previous != cell {
for index in [previous, cell].into_iter().flatten() {
if let Some(history_cell) = self.cells.get(index) {
self.view.renderables[index] = Self::render_cell(
history_cell,
index,
self.highlight_cell,
self.history_state,
);
}
}
}
if let Some(idx) = self.highlight_cell {
self.view.scroll_chunk_into_view(idx);
}