Skip to content

feat(editor): add opt-in collapsed unchanged regions for file diffs - #11955

Merged
nwparker merged 4 commits into
stablyai:mainfrom
dcieslak19973:dcieslak19973/collapse-unchanged-diff-regions
Sep 19, 2026
Merged

nwparker merged 4 commits into
stablyai:mainfrom
dcieslak19973:dcieslak19973/collapse-unchanged-diff-regions

Conversation

@dcieslak19973

@dcieslak19973 dcieslak19973 commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What: Opt-in collapse of unchanged regions in single-file diffs, matching what "View All Changes" already does.
Risk: One boolean setting, default off — no behavior change without explicit user action. Greptile: 5/5 "Safe to merge".
State: Rebased on main today (0 behind, 0 conflicts); all review-bot threads resolved.

ELI5

Today, opening a single file's diff shows every line of the file even if only one line changed, so reviewing a small edit in a long file means a lot of scrolling. This adds an optional Settings > General > Editor switch, "Collapse Unchanged Regions" (off by default), that hides untouched stretches behind expandable "hidden lines" bands — the same way the existing View All Changes view already behaves. Nothing changes unless you turn it on.


Summary

The combined "View All Changes" diff already collapses runs of unchanged lines into expandable bands — DiffSectionBody.tsx sets Monaco's hideUnchangedRegions: { enabled: true }. A single-file diff opened by clicking one file in Source Control does not, so it renders the whole file. Reviewing a one-line change in a long file means scrolling past everything that did not change.

This adds a General → Editor setting, default off, that applies the same Monaco option to the single-file diff viewer. Off preserves today's full-file rendering for everyone who has not opted in.

One detail worth noting: the option is always emitted rather than omitted when the setting is off. Monaco retains the last applied value across an options update, so dropping the key would strand an already-open diff in collapsed mode after the user turns the setting back off. buildDiffEditorHideUnchangedOptions therefore returns an explicit { enabled: false }, and a test pins that.

Screenshots

No new chrome. The setting is one segmented Off/On control in General → Editor, sitting directly above the existing "Diff Word Wrap" control and matching its shape. When enabled, single-file diffs render exactly as the existing View All Changes diff already does — unchanged runs become clickable "N hidden lines" bands.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (939 settings/editor/shared tests pass)
  • pnpm build — not run locally; relies on CI
  • Added or updated high-quality tests that would catch regressions

diff-editor-hide-unchanged-options.test.ts covers on, off, and the legacy-undefined case, including the always-emit-the-key behavior described above.

AI Review Report

Reviewed with Claude Code. Risks checked: Monaco option lifecycle across settings changes and model swaps, settings persistence and defaulting for existing profiles, and consistency with the combined diff surface.

  • Stale option on toggle-off — found and handled; see the Summary note. This is the one behavior here that is not obvious from the diff.
  • Legacy settings — the field is optional (diffCollapseUnchangedRegions?: boolean) and every read goes through === true, so profiles written before this change behave exactly as they do today without a migration.
  • Surface consistency — the combined viewer keeps its unconditional hideUnchangedRegions. This PR deliberately does not put that surface behind the setting: it is a summary view where collapsing is the point, and changing it would be a behavior regression for existing users.
  • Max-lines — the setting was initially written inline in GeneralEditorSettingsSection.tsx, which pushed it to 437 lines against the repo's 400 ceiling. Rather than add a max-lines disable (which AGENTS.md forbids outright), it is extracted into its own CollapseUnchangedRegionsSetting.tsx, matching the one-setting-per-file pattern already used by CompareAgainstUpstreamSetting and others.

Cross-platform: no platform-dependent code. This is a single Monaco editor option plus a settings boolean — no shortcuts, labels, paths, shell behavior, or Electron platform APIs are touched.

Security Audit

Minimal surface. No IPC, command execution, path handling, auth, secrets, or dependency changes. The only new persisted value is a boolean flowing through the existing settings store, consumed as a Monaco rendering option. No user input reaches any new sink. No follow-up needed.

Notes

Independent of #11866 and #11867 — no shared files, applies cleanly on its own.

Worth flagging for maintainers: the discoverability gap here is real. A user looking for "show me only the changed lines" would reasonably expect that from the per-file diff and may not find that View All Changes already does it. If you would rather this default on for parity with the combined view, that is a one-line change to constants.ts — I defaulted it off to avoid changing behavior for existing users without opt-in.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds the optional diffCollapseUnchangedRegions global setting with a default of false. Adds a localized control in the general editor settings section. Maps the setting to Monaco diff-editor options in DiffViewer. Adds tests for true, false, and undefined values.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the change and testing, but it omits the required linked issue and visual proof attachments for this UI behavior change. Add a valid “Fixes #” issue reference and attach before/after visual proof; complete or explicitly address the remaining template sections and checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the opt-in collapsed unchanged regions feature for editor diffs.

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds an opt-in setting ("Collapse Unchanged Regions") to the General → Editor settings panel that applies Monaco's hideUnchangedRegions option to single-file diff views, matching the behavior already present in the combined "View All Changes" diff. The setting defaults to false to avoid changing behavior for existing users.

  • New utility + tests: buildDiffEditorHideUnchangedOptions always emits an explicit { enabled: false } when the setting is off (not absent), preventing Monaco from stranding an already-open diff in collapsed mode on toggle-off. The test suite pins this behavior across all three input cases (true, false, undefined).
  • Backward compatibility: diffCollapseUnchangedRegions is typed as boolean | undefined (optional) in GlobalSettings, and the utility uses === true for the check, so existing profiles without the key behave identically to today without any migration.

Confidence Score: 5/5

Safe to merge. The change is well-scoped: a new optional boolean in settings, a small Monaco options utility with explicit tests, and an extracted UI component following existing patterns.

The always-emit-the-key design (returning enabled: false rather than omitting the field) correctly handles the Monaco option-lifecycle edge case. Legacy settings with undefined flow through the same guard (=== true). The new field is optional in the type and has a false default so no migration is needed. No auth, IPC, path handling, or dependency changes are introduced.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/editor/diff-editor-hide-unchanged-options.ts New utility that maps the setting boolean to Monaco's hideUnchangedRegions option; always emits the key (never omits it) to handle toggle-off correctly.
src/renderer/src/components/editor/diff-editor-hide-unchanged-options.test.ts Tests cover all three input cases (true, false, undefined) and pin the always-emit-the-key behavior.
src/renderer/src/components/editor/DiffViewer.tsx Spreads buildDiffEditorHideUnchangedOptions into the Monaco options object, consistent with the existing diffWordWrap pattern.
src/renderer/src/components/settings/CollapseUnchangedRegionsSetting.tsx Extracted UI component following the one-setting-per-file pattern; correctly handles undefined (falsy) for the Off default state.
src/renderer/src/components/settings/GeneralEditorSettingsSection.tsx Inserts CollapseUnchangedRegionsSetting between EditorWordWrapSetting and the Diff Word Wrap control; stays within the 400-line limit via extraction.
src/shared/types.ts Adds optional diffCollapseUnchangedRegions?: boolean to GlobalSettings for backward compatibility with existing profiles.
src/shared/constants.ts Adds diffCollapseUnchangedRegions: false to getDefaultSettings; new profiles default to off.
src/renderer/src/i18n/locales/en.json Adds collapseUnchangedTitle and collapseUnchangedDescription using descriptive camelCase keys, consistent with sibling settings in the same namespace.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User toggles setting in\nGeneral → Editor] --> B[updateSettings diffCollapseUnchangedRegions]
    B --> C[GlobalSettings store updated]
    C --> D[DiffViewer re-renders\nsettings?.diffCollapseUnchangedRegions]
    D --> E[buildDiffEditorHideUnchangedOptions]
    E -->|true| F[hideUnchangedRegions: enabled true]
    E -->|false / undefined| G[hideUnchangedRegions: enabled false\nalways emitted — never omitted]
    F --> H[Monaco DiffEditor.updateOptions]
    G --> H
    H -->|enabled: true| I[Unchanged regions collapse\ninto expandable bands]
    H -->|enabled: false| J[Full file rendered\ndefault behavior]
    K[DiffSectionBody.tsx\nView All Changes] -->|unconditional| L[hideUnchangedRegions: enabled true\nnot affected by this setting]
Loading

Reviews (2): Last reviewed commit: "feat(editor): add opt-in collapsed uncha..." | Re-trigger Greptile

Comment thread src/renderer/src/i18n/locales/en.json Resolved
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch 3 times, most recently from ff8e205 to bbffe72 Compare August 4, 2026 21:08
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from bbffe72 to e8a96bb Compare August 5, 2026 00:15
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from e8a96bb to ccb0dcf Compare August 5, 2026 04:16
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from ccb0dcf to 6e80059 Compare August 5, 2026 19:06
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from 6e80059 to c777b51 Compare August 7, 2026 02:32
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch 2 times, most recently from 06f4695 to f11c89c Compare August 19, 2026 01:39
@nwparker nwparker removed the P2 label Aug 19, 2026
@nwparker
nwparker force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from f11c89c to 84d7fd7 Compare August 23, 2026 23:36
@nwparker

Copy link
Copy Markdown
Contributor

Readiness pass — rebased, fixed, and validated in the real app

Rebased onto current main (was 151 commits behind; clean rebase, no conflicts) and force-pushed with an exact lease against the prior head f11c89c.

One real gap found and fixed

The setting shipped its own SearchableSetting with keywords, but was never registered in the General pane's section catalog (general-editor-search.ts). Because the pane only renders when the section catalog matches, searching Settings for "collapse unchanged" returned "No settings found" — the setting was effectively unreachable via search. Verified live in Electron before the fix, then again after.

Fix commit: 84d7fd7 — adds the catalog entry (+ en.json keys) and a regression test that asserts the entry is reachable for collapse unchanged, collapse, hide unchanged, fold, and diff.

Visual proof (uncropped, real Electron dev build)

Fixture: a 120-line file with three sparse edits (lines 10, 60, 110).

1. Setting OFF (default) — full file rendered, nothing hidden
01-collapse-off.png

2. Setting discoverable in Settings search (this is the fix)
02-settings-search.png

3. Setting ON — collapsed bands around each change
6 hidden lines / 43 hidden lines / 43 hidden lines / 8 hidden lines, three lines of context per change.
03-collapse-on.png

4. Expansion works — clicking a band's expand control shrinks it 43 → 23 hidden lines
04-band-expanded.png

5. Toggling back OFF un-collapses the live editor in place
This is the regression diff-editor-hide-unchanged-options.test.ts guards (Monaco retains the last applied hideUnchangedRegions value, so the option must be emitted explicitly when off rather than omitted). Confirmed on screen, not just in the store.
05-toggled-back-off.png

Verification run

Gate Result
vitest — diff-editor-hide-unchanged-options, general-editor-search, settings-search, EditorWordWrapSetting 13 passed
pnpm typecheck (node + cli + web + e2e) clean
oxlint — components/settings/, components/editor/ clean
oxfmt --check clean
verify:localization-catalog 12327 key references verified
verify:localization-extraction passed
verify:localization-coverage passed
check:max-lines-ratchet no new bypasses
check:reliability-gates 88 gates passed
pnpm build:electron-vite built

Notes / remaining gaps

  • Non-English locales fall back to English for the new strings, consistent with how other recently-added settings land.
  • Validated on macOS only. The change is Monaco-option and settings-catalog level with no platform-dependent code paths, so cross-platform risk is low.
  • SSH / remote-host and folder-workspace cases are unaffected: this is a renderer-only diff-editor option driven by a global setting.
  • Combined "View All Changes" diff (DiffSectionBody) still enables hideUnchangedRegions unconditionally — unchanged by this PR, and the setting copy states this.

@nwparker

Copy link
Copy Markdown
Contributor

CI result on 84d7fd7

44 success · 1 skipped · 1 failure · 1 queued (verify, gated on the shard matrix). mergeable: true, state unstable because of the single failure below.

The one failure is unrelated to this PR and looks like a flake:

FAIL src/main/runtime/orca-runtime.test.ts > OrcaRuntimeService >
  fences provider resume and reveals one exact live legacy worker without stealing focus
AssertionError: expected "vi.fn()" to be called 6 times, but got 7 times
  ❯ src/main/runtime/orca-runtime.test.ts:20835:37
Test Files  1 failed | 381 passed | 3 skipped (385)
Tests       1 failed | 4707 passed | 21 skipped (4729)

Evidence that it is not caused by this change:

  • It is main-process runtime/terminal-orchestration code. This PR touches only the renderer diff editor, a settings component, the settings-search catalog, and en.json — no overlap with orca-runtime.ts or its spies.
  • The identical shard (4/16) passed on Node 26; only the Node 24 copy failed.
  • The test passes locally on this exact PR head (1 passed | 1185 skipped).
  • The assertion is an off-by-one on a spy call count (6 vs 7) — a timing/ordering shape, not a behavioral break.

I could not re-run the shard (gh run rerun refuses for this fork-PR run). A maintainer re-run of tests node 24 4/16 should clear it; happy to push a no-op commit to retrigger the matrix if that is preferred.

Everything in the previous comment's verification table still stands, all run locally against this head.

@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from 84d7fd7 to 8809559 Compare August 28, 2026 04:04
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch 2 times, most recently from d828009 to dc3f03e Compare September 10, 2026 12:56
The combined "View All Changes" diff already collapses unchanged lines into
expandable bands (DiffSectionBody sets Monaco's hideUnchangedRegions), but a
single-file diff opened from Source Control renders the whole file. Reviewing
one changed line in a long file means scrolling past everything else.

Adds a General > Editor setting, default off, that applies the same Monaco
option to the single-file diff viewer. Off keeps today's full-file rendering.

The option is always emitted rather than omitted when off: Monaco retains the
last applied value across an options update, so dropping the key would strand
an open diff in collapsed mode after the setting is turned back off.

Co-Authored-By: Claude Opus 5 <[email protected]>
@dcieslak19973
dcieslak19973 force-pushed the dcieslak19973/collapse-unchanged-diff-regions branch from dc3f03e to 7dfe6b1 Compare September 11, 2026 13:37
@nwparker
nwparker merged commit 3e7da29 into stablyai:main Sep 19, 2026
1 check passed
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.

4 participants