Skip to content

Fix diff viewer scroll sync and add context folding#121

Merged
actionshrimp merged 1 commit intomainfrom
fix/diff-viewer-scroll-sync-and-folds
Mar 8, 2026
Merged

Fix diff viewer scroll sync and add context folding#121
actionshrimp merged 1 commit intomainfrom
fix/diff-viewer-scroll-sync-and-folds

Conversation

@actionshrimp
Copy link
Owner

Summary

  • Fix scroll sync jankiness in both 2-pane and 3-pane diff views by suspending scrollbind during content replacement, resetting cursor positions between file switches, and deferring syncbind via vim.schedule to let pending buffer operations settle
  • Add BufEnter autocmd on diff buffers to re-sync scrollbind when a window gains focus, recovering from desync caused by mouse-scrolling an inactive window (Vim's intentional "quickadj" behavior)
  • Add context folding to 2-pane diffs — large context-only regions are now folded with 3 lines of context around each change, matching the existing 3-way diff behavior

Test plan

  • All 643 existing tests pass (55 suites)
  • 7 new unit tests for compute_fold_ranges covering: empty input, all-changes input, inter-hunk folding, leading context, trailing context, custom context_lines, single-line gap rejection

Scroll sync was janky because scrollbind stayed active during content
replacement (causing windows to fight each other), cursor positions
weren't reset between file switches, and there was no recovery from
mouse-scroll-induced desync.

Fixes:
- Suspend scrollbind during content update, reset cursors to {1,0},
  then re-enable with deferred syncbind via vim.schedule
- Add BufEnter autocmd on diff buffers to re-sync scrollbind when
  focusing a window (recovers from mouse scroll on inactive window)
- Apply same fixes to both 2-pane and 3-pane buffer modules

Also adds context folding to 2-pane diffs (previously only 3-pane had
this): large context-only regions are folded with 3 lines of context
shown around each change, matching the existing 3-way behavior.
@actionshrimp actionshrimp merged commit 1bbf513 into main Mar 8, 2026
3 checks passed
@actionshrimp actionshrimp deleted the fix/diff-viewer-scroll-sync-and-folds branch March 8, 2026 16:36
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