Skip to content

fix(app): collapse commit diff files from their header - #4467

Closed
CN-liuzhiyang wants to merge 1 commit into
getpaseo:mainfrom
CN-liuzhiyang:fix/commit-diff-collapse
Closed

fix(app): collapse commit diff files from their header#4467
CN-liuzhiyang wants to merge 1 commit into
getpaseo:mainfrom
CN-liuzhiyang:fix/commit-diff-collapse

Conversation

@CN-liuzhiyang

Copy link
Copy Markdown

Linked issue

Closes #

Type of change

  • Bug fix

Reasoning

Clicking a file header in the working diff collapses that file. The same header in a commit diff does nothing — it is not even pressable. Nothing about collapsing is specific to the working tree; a commit that touches twenty files is exactly where you want to fold away the ones you have already read.

The reason it was missing is structural: collapseState was declared on the working branch of the DiffDocumentProps union, so the commit panel had no way to pass one, and DocumentFileHeader returned early on any non-working mode.

Goals

  • A commit diff file header collapses and expands on press, like the working diff.
  • Collapsed paths persist per tab, like the Changes panel.
  • Right click on a commit diff header does not regress.

Non-goals

  • No file-actions menu (Open file, Revert, Add to chat) on commit diff headers. Those are working-tree actions and the commit panel owns none of them.

Implementation notes

collapseState moves onto the document's base props so both modes toggle.

FileHeader separates the two things interactive used to mean. Press and hover now follow onActivate; the drag source and the file-actions menu stay behind interactive, which the commit diff does not set. Without that split a commit header would mount a ContextMenu whose content renders null, and right click would be swallowed for a menu that never appears.

That is also why ContextMenuTrigger changes: a trigger with enabled={false} still called preventDefault/stopPropagation, so it ate the right click and showed nothing. It now lets the event through, and the diff surface's own Copy / Copy line / Select all menu still opens over a commit diff header. No existing caller passes enabled={false}, so nothing else changes.

QA

Automated, on this branch:

$ npm run typecheck
(all workspaces, no errors)

$ npm run lint
Found 0 warnings and 0 errors.

$ npx vitest run src/components/ui/context-menu.test.tsx src/git/use-diff-files.test.ts --bail=1
 Test Files  2 passed (2)
      Tests  3 passed (3)

New browser coverage in packages/app/e2e/browser/commit-diff-panel.spec.ts:

test("a commit diff file collapses and expands from its header", ...)
  await panel.getByTestId("diff-file-0").click();
  await expect(panel.getByTestId("diff-file-0-body")).not.toBeVisible();
  await panel.getByTestId("diff-file-0").click();
  await expect(panel.getByTestId("diff-file-0-body")).toBeVisible();

Manual, Windows desktop, against a real daemon in a real browser, through the same steps the spec runs (Changes → Commits → commit row):

Expanded:

expanded

After pressing the feature.txt header:

collapsed

Pressing again restores the body. Right clicking the header still opens the diff Copy / Copy line / Select all menu.

Platform Tested Notes
iOS Shares the DocumentFileHeader path with web; not run on device
Android Same
Web yes Playwright browser project
Desktop macOS
Desktop Windows yes Electron dev build
Desktop Linux

commit-diff-panel.spec.ts could not be run locally: on this machine the withWorkspace fixture never gets past "No projects yet", and it fails the same way on a clean checkout of main, so it is an environment problem rather than something this branch introduced. The collapse behaviour above was verified through a seedWorkspace-based run of the identical steps. CI covers the committed spec.

Checklist

  • One focused change
  • npm run typecheck passes
  • npm run lint passes
  • npm run format passes
  • QA evidence
  • Tests added or updated where it made sense

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR allows commit-diff files to be collapsed from their headers while preserving working-tree-only actions and allowing right-click events to reach the surrounding diff menu.

  • Moves collapse state into the shared diff-document contract and persists commit-diff collapsed paths in panel state.
  • Separates header activation from working-tree interactivity so commit headers can collapse without exposing file actions or drag behavior.
  • Makes disabled context-menu triggers transparent to right-click propagation.
  • Adds browser coverage for collapsing and expanding a commit-diff file.

Confidence Score: 4/5

The runtime change appears sound, but the existing repository-rule violation in the commit-diff E2E selector must still be corrected before merging.

The previous right-click propagation defect is fixed because a disabled trigger returns before selecting the row or stopping the event. The previous E2E finding is only partly fixed: navigation mechanics were extracted and the test body is now concise, but the helper still locates a user-visible commit row through [data-testid^="commit-row-"] rather than an accessible role and name, so that rule-backed finding remains outstanding.

Files Needing Attention: packages/app/e2e/browser/commit-diff-panel.spec.ts

Important Files Changed

Filename Overview
packages/app/src/git/diff-document/types.ts Makes collapse state a required shared capability for both working and commit diff modes.
packages/app/src/git/file-header.tsx Separates pressability from working-tree actions and leaves disabled context-menu triggers transparent.
packages/app/src/components/ui/context-menu.tsx Prevents disabled web triggers from consuming context-menu events.
packages/app/src/panels/diff-panel.tsx Persists and supplies collapsed file paths for commit-diff panels.
packages/app/e2e/browser/commit-diff-panel.spec.ts Adds collapse/expand coverage and extracts navigation mechanics, but retains the accessible-selector violation tracked by the prior review thread.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Commit diff file header] -->|Primary press| B[DocumentFileHeader activate]
    B --> C[Toggle path in collapse state]
    C --> D[Persist commit panel state]
    D --> E[Hide or show diff file body]
    A -->|Right click| F[Disabled file-actions trigger]
    F -->|Event propagates| G[Outer diff-surface context menu]
Loading

Reviews (2): Last reviewed commit: "fix(app): collapse commit diff files fro..." | Re-trigger Greptile

if (isNative) return;
// A disabled trigger owns no menu, so it must let the event reach whatever
// encloses it instead of swallowing the right click and showing nothing.
if (!shouldEnableOnThisPlatform || disabled) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Parent menu remains blocked

When a commit header is right-clicked, this disabled trigger now lets the event bubble, but WebFileHeaderSection stops it before it reaches the outer diff-surface trigger. As a result, the Copy, Copy line, and Select all menu still does not open over commit headers, so the right-click fix is incomplete.

const commitsSection = page.getByRole("button", { name: /Commits/i });
await expect(commitsSection).toBeVisible({ timeout: 30_000 });
await commitsSection.click();
await page.locator('[data-testid^="commit-row-"]').filter({ hasText: COMMIT_SUBJECT }).click();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 E2E test violates requirements

This helper uses a CSS attribute selector for a user-visible commit row, and the related test body directly performs 12 lines of setup, navigation, clicks, and assertions. The repository requires accessible role/name selectors for visible controls and E2E bodies of roughly 3–8 lines of user intent, with browser mechanics moved into helpers. These requirements must be satisfied before merging.

Rule Used: # Code Review Pattern Reference: Slop, Tests, Feat... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

The commit diff rendered file headers that could not be pressed, while the
working diff collapsed a file on click. Collapse state was declared on the
working branch of the DiffDocument props union, so the commit panel had no
way to pass one, and DocumentFileHeader returned early on any non-working
mode.

Move collapseState onto the document's base props and let both modes toggle.
FileHeader now separates the two things `interactive` used to mean: press and
hover follow onActivate, while the drag source and the file-actions menu stay
behind `interactive`, which the commit diff does not have. A disabled
ContextMenuTrigger no longer swallows the right click, so a header without its
own menu still lets the diff's Copy/Select all menu through.

The commit panel persists collapsed paths per tab, matching the Changes panel.
@CN-liuzhiyang
CN-liuzhiyang force-pushed the fix/commit-diff-collapse branch from 06cf0cc to a4b4615 Compare September 8, 2026 07:24
@boudra

boudra commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Closing this commit-diff folding proposal. Please discuss the workflow and shared need in Discussions, following CONTRIBUTING.md.

@boudra boudra closed this Sep 8, 2026
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.

2 participants