Open /diff in a TUI sidebar tab (#64258)

## Why

The full-screen diff pager takes the conversation off screen. A sidebar tab lets users review working-tree changes alongside the conversation.

## What changed

- Open a read-only `Diff` tab when the sidebar is available, and fall back to the full-screen pager otherwise.
- Reuse the tab on repeated runs. Keep the previous patch visible while Git runs, preserve the reading position on refresh, and apply only the latest result without stealing focus.
- Render large patches in chunks and derive scroll indicators from visible rows so redraws can skip layout of the off-screen tail.

## Testing

Cover tab reuse, stale result handling, and the visibility of the last hunk across resize and refresh. Verify that scroll indicators render without laying out the off-screen tail.

GitOrigin-RevId: 812ea99896dfd3131af9cf356cb844f4f0f7c267
This commit is contained in:
Felipe Coury
2026-11-27 04:54:59 +00:00
committed by copyberry
parent fe6dca3422
commit cd30214700
17 changed files with 706 additions and 121 deletions
+18 -3
View File
@@ -96,6 +96,11 @@ struct VisibleRow {
activity_ids: Arc<[String]>,
}
enum RenderContent {
Transcript,
Document,
}
/// Shared scrolling and interaction state for compact and detailed transcript presentations.
pub(crate) struct TranscriptView {
pub(crate) image_protocol: Option<crate::pets::ImageProtocol>,
@@ -217,11 +222,17 @@ impl TranscriptView {
}
pub(crate) fn render(&mut self, area: Rect, buf: &mut Buffer, cells: &[Arc<dyn HistoryCell>]) {
self.paint_rows(area, buf, cells);
self.paint_rows(area, buf, cells, RenderContent::Transcript);
self.finish_collapse_layout(cells);
}
fn paint_rows(&mut self, area: Rect, buf: &mut Buffer, cells: &[Arc<dyn HistoryCell>]) {
fn paint_rows(
&mut self,
area: Rect,
buf: &mut Buffer,
cells: &[Arc<dyn HistoryCell>],
content: RenderContent,
) {
let previous_viewport_height =
self.area.height + u16::from(self.prompt_header_target.is_some());
self.composer_tip = None;
@@ -379,7 +390,11 @@ impl TranscriptView {
{
self.extend_selection(pointer.x, pointer.y);
}
self.tail_visible = self.current_tail_is_visible(current_cells);
self.tail_visible = match content {
RenderContent::Transcript => self.current_tail_is_visible(current_cells),
// Documents have immutable chunks and no hidden reasoning or live tail.
RenderContent::Document => !self.document_has_rows_below(cells),
};
if self.tail_visible {
self.unseen_activity = false;
}