Skip to content

fix(staged): select first file from sidebar order instead of raw git order#717

Merged
matt2e merged 2 commits into
mainfrom
open-diff-first-file
May 13, 2026
Merged

fix(staged): select first file from sidebar order instead of raw git order#717
matt2e merged 2 commits into
mainfrom
open-diff-first-file

Conversation

@matt2e

@matt2e matt2e commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When the diff modal opens, the initially selected file now matches the first file in the sidebar's display order (needs-review → reviewed) instead of using raw git diff order
  • Resets the selection flag when switching diff context so the correct first file is picked after reload

Test plan

  • Open a diff with multiple changed files and verify the first file shown matches the top of the sidebar
  • Switch between commits/scopes and confirm the first sidebar file is auto-selected each time

🤖 Generated with Claude Code

…order

When a diff opens, the initial file selection used `state.files[0]` from
the raw git response (sorted by full path), which could differ from the
first file shown in the sidebar (sorted per-directory with dirs first).
Add a reactive effect in DiffModal that overrides the initial selection
with `orderedFiles[0]` once files finish loading, keeping the viewer and
sidebar in sync. The flag resets on context switches so it re-fires for
new file sets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
@matt2e matt2e requested review from baxen and wesbillman as code owners May 12, 2026 09:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bafae077e3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +750 to +752
if (!diffViewer.state.loading && orderedFiles.length > 0 && !initialSelectionApplied) {
initialSelectionApplied = true;
diffViewer.selectFile(orderedFiles[0].path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wait for review state before locking initial selection

When opening an existing non-readonly review, reviewHandle.state.reviewedPaths is populated asynchronously by createReviewState, but this effect marks initialSelectionApplied as soon as diff files finish loading. If the review load resolves after diffViewer.state.loading becomes false, orderedFiles is still computed with every file as needs-review, so a file that is already reviewed can be selected and the later reviewed-path update cannot correct it because the flag is already true. This still leaves the initial file out of sync with the needs-review → reviewed sidebar order for saved reviews with reviewed files.

Useful? React with 👍 / 👎.

When opening an existing review, the initial file selection effect fired
as soon as diff files loaded, before reviewedPaths finished loading from
the backend. This meant orderedFiles was computed with all files in the
needs-review bucket, so the selected file could differ from the actual
sidebar order once reviewed paths arrived.

Add a guard that also waits for reviewHandle.state.loading to be false
before applying the initial selection, ensuring the needs-review vs
reviewed split is accurate when picking the first file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
@matt2e matt2e merged commit ef53da2 into main May 13, 2026
5 checks passed
@matt2e matt2e deleted the open-diff-first-file branch May 13, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant