Skip to content

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

Merged
jonathanlab merged 4 commits intoPostHog:mainfrom
CaioDGallo:feat/diff-context-expand
Mar 31, 2026
Merged

feat(code-editor): add collapse unchanged lines extension with expand…#1342
jonathanlab merged 4 commits intoPostHog:mainfrom
CaioDGallo:feat/diff-context-expand

Conversation

@CaioDGallo
Copy link
Copy Markdown
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

@CaioDGallo CaioDGallo force-pushed the feat/diff-context-expand branch from 4e94d73 to 4ae9a13 Compare March 29, 2026 11:12
@jonathanlab jonathanlab self-assigned this Mar 31, 2026
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab left a comment

Choose a reason for hiding this comment

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

Thank you! I ran into some smaller issues:

  • expand up and expand down seem to do the opposite of what they're supposed to do (expandDown for example reveals the top)
  • this does not work in split view, only in unified view.
  • It wasn't entirely clear to me that clicking the line count would expand the entire section if we could expand both up and down
  • We should indicate how many lines the user will expand if they can expand up and down.

I'll make some small adjustments then merge it!

@CaioDGallo CaioDGallo force-pushed the feat/diff-context-expand branch from 283e948 to ffa0f0e Compare March 31, 2026 10:43
@jonathanlab
Copy link
Copy Markdown
Contributor

jonathanlab commented Mar 31, 2026

image

I updated it to this.

@jonathanlab jonathanlab force-pushed the feat/diff-context-expand branch from ffa0f0e to 98ec4e6 Compare March 31, 2026 10:51
@CaioDGallo
Copy link
Copy Markdown
Contributor Author

Thanks for the follow up, @jonathanlab! The updated version looks much cleaner. I don’t know why, but I definitely had a "wires crossed" moment with those expand directions, I might have changed them 3 or 4 times. Thanks for straightening that out! Appreciate you jumping in to polish those bits.

@jonathanlab jonathanlab merged commit ba243a7 into PostHog:main Mar 31, 2026
15 checks 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.

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

2 participants