Skip to content

feat(code-editor): add collapse unchanged lines extension with expand…#1342

Open
CaioDGallo wants to merge 1 commit intoPostHog:mainfrom
CaioDGallo:feat/diff-context-expand
Open

feat(code-editor): add collapse unchanged lines extension with expand…#1342
CaioDGallo wants to merge 1 commit intoPostHog:mainfrom
CaioDGallo:feat/diff-context-expand

Conversation

@CaioDGallo
Copy link
Contributor

@CaioDGallo CaioDGallo commented Mar 26, 2026

Problem

The built-in collapseUnchanged option from @codemirror/merge doesn't support gradual expand controls (expand up/down N lines). Users viewing diffs with large unchanged regions had no way to incrementally reveal context; they could only see the collapsed placeholder or load full ranges of unchanged lines between diffs.

Closes #1341

Changes

  • Added a custom CodeMirror extension that replaces the built-in collapseUnchanged with an expand-enabled collapse widget. Unchanged regions are collapsed with up/down arrow buttons to expand 20 lines at a time, plus a "N unchanged lines" label that expands all. Expand actions are synced across both sides of split-merge views via mergeViewSiblings.
  • Removed the built-in collapseUnchanged config and wired the new extension into both split and unified merge views. The extension is skipped when loadFullFiles is true.
  • Replaced the old .cm-collapsedLines gradient styles with new .cm-collapsed-context, .cm-collapsed-gutter, .cm-collapsed-expand-btn, and .cm-collapsed-label styles supporting light/dark themes with hover states.
  • Added unit tests covering mapPosBetweenSides, buildDecorations, applyExpandEffect (expand up/down/all), and computeInitialRanges (mocked via buildDecorations assertions).

How did you test this?

  • Unit tests for all pure logic functions
  • Manual testing in the code editor: verified collapse/expand behavior in split and unified diff views, light and dark themes, and with loadFullFiles toggled

Feature Examples

Before

image1

After

image3 image2 image5 image4

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.

Add incremental context expansion (up/down arrows) to diff viewer

1 participant