Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/staged/src/lib/features/diff/DiffModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@
// Reset review state — the $effect will recreate it once the new commitSha resolves
reviewHandle = null;

// Reset so the sidebar-order effect picks the first file after reload
initialSelectionApplied = false;

// Switch diff context (reloads file list)
try {
await diffViewer.switchContext(newScope, newCommitSha);
Expand Down Expand Up @@ -740,6 +743,23 @@
: [...flattenTreeFiles(needsReviewTree), ...flattenTreeFiles(reviewedTree)]
);

// Once files finish loading, override the initial selection with the first
// file in sidebar order so the viewer and sidebar stay in sync.
// For non-readonly reviews, also wait for reviewedPaths to load so the
// needs-review / reviewed split is accurate before picking the first file.
let initialSelectionApplied = false;
$effect(() => {
if (
!diffViewer.state.loading &&
orderedFiles.length > 0 &&
!initialSelectionApplied &&
(readonly || !reviewHandle || !reviewHandle.state.loading)
) {
initialSelectionApplied = true;
diffViewer.selectFile(orderedFiles[0].path);
}
});

// ==========================================================================
// Sidebar interactions
// ==========================================================================
Expand Down