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
+4 -35
View File
@@ -87,7 +87,7 @@ impl ChatWidget {
/// Re-anchor the local daemon's sandbox at the session cwd. A profile ID
/// cannot carry extra runtime roots or permissions from a remote executor.
pub(super) fn diff_permission_profile(&self) -> Option<String> {
pub(crate) fn diff_permission_profile(&self) -> Option<String> {
if !self.remote_connection.as_ref()?.is_local_daemon {
return None;
}
@@ -543,40 +543,9 @@ impl ChatWidget {
}
SlashCommand::Tui => self.show_tui_mode_picker(),
SlashCommand::Diff => {
self.add_diff_in_progress();
let tx = self.app_event_tx.clone();
let runner = self.workspace_command_runner.clone();
let thread_id = self.thread_id();
let cwd = self.session_cwd().clone();
let profile = self.diff_permission_profile();
tokio::spawn(async move {
let text = match runner {
Some(runner) => {
match get_git_diff(
runner.as_ref(),
&cwd.to_path_buf(),
profile.as_deref(),
)
.await
{
Ok((is_git_repo, diff_text)) => {
if is_git_repo {
diff_text
} else {
"`/diff` — _not inside a git repository_".to_string()
}
}
Err(e) => format!("Failed to compute diff: {e}"),
}
}
None => "Failed to compute diff: workspace command runner unavailable"
.to_string(),
};
tx.send(AppEvent::DiffResult {
thread_id,
cwd,
text,
});
self.app_event_tx.send(AppEvent::OpenDiff {
thread_id: self.thread_id(),
cwd: self.session_cwd().clone(),
});
}
SlashCommand::Mention => {