Skip to content

feat(diff): context collapse threshold + word wrap#53

Open
hewigovens wants to merge 4 commits into
mainfrom
perf/jj-diff-context-threshold
Open

feat(diff): context collapse threshold + word wrap#53
hewigovens wants to merge 4 commits into
mainfrom
perf/jj-diff-context-threshold

Conversation

@hewigovens
Copy link
Copy Markdown
Owner

@hewigovens hewigovens commented May 21, 2026

Summary

Three commits carved out of #46. The word-wrap commit needs manual testing — there is no automated end-to-end coverage for the GPUI/AppKit text layout.

1. perf(jj-diff): keep short context runs uncollapsed

  • Don't collapse runs of unchanged context <= COLLAPSED_CONTEXT_THRESHOLD (2) lines — render them inline instead of as an "N unmodified lines" stub.
  • Rename separator placeholder from "N hidden lines" → "N unmodified lines" for consistency.
  • Multi-line signature for compute_file_diff_full; new threshold tests.
  • Review fixes: merged duplicate early-return blocks; dropped unreachable if hidden == 0 guard.

2. feat(diff): word wrap for unified and side-by-side diff views

GPUI shell:

  • New shell/gpui/src/diff/wrap.rswrap_diff_lines, wrap_sbs_rows, wrap_cols_from_bounds, selection_cols_in_fragment, visual_index_for_line.
  • Updated diff_view/unified_body.rs, diff_view/sbs_body.rs, diff_view/mouse.rs, selection.rs, annotate_view.rs.
  • log/find.rs translates find-match line indices to visual rows. SBS path chains sbs_line_to_row (pairing-aware) → visual_index_for_sbs_row so find-next in SBS centers on the correct wrapped row.

SwiftUI shell (JayJayDiffUI package):

  • New NativeDiffView+WrappedGutter.swift.
  • Updated NativeDiffView.swift, DiffGutterTextView.swift, DiffTextContainerView.swift, DiffTextSupport.swift, NativeDiffView+Gutter.swift, SideBySideDiffRendering.swift to support wrapped rendering with gutter alignment.
  • DiffTextContainerView now exposes wrapsText: Bool (default true). SBS (SideBySideDiffView) sets both panes' containers to false — per-side wrapping would desync the panes and gutters until we ship "wrap to tallest side + continuation rows". Unified view still wraps.
  • DiffLayoutManagerTests.swift updated.

3. fix(core): rename backout → revert_change and land on @

Crown-jewel fix carved out of #46:

  • repo.backout() mis-passed --insert-after rev, leaving the revert as a child of the change being reverted instead of on top of @. Rename to revert_change and pass --onto @ to match jj revert semantics.
  • uniffi + Swift call sites renamed: JayJayRepo.revert_change, ChangeActions.revertChange, callers in DAGView, RepoContentView+CommandPalette, and the RepoViewModel impl.
  • real_jj_repo test rewritten: now asserts the working-copy description stays at child change, the revert change appears in log, and its parent is @.
  • Docs (CONTRIBUTING.md, README.md, docs/index.html) updated to the revert terminology.

Test plan

  • cargo test -p jj-diff (perf threshold cases)
  • cargo test -p jayjay-core (incl. revert_change_uses_jj_revert_and_creates_reverse_change)
  • cargo clippy -p jj-diff -p jayjay-gpui --all-targets -- -D warnings
  • just test-gpui and just test-app
  • just build (full Swift app + regenerated uniffi bindings)
  • Manual: open a wide diff in unified and SBS modes (GPUI + SwiftUI), resize the pane, verify wrap + gutter alignment + selection + find-jump.
  • Manual: trigger Revert Change from DAG context menu and the command palette; verify the new revert change lands as a child of @.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the diff engine to use histogram line matching and introduces 'tiny-gap auto-expansion' to prevent collapsing small sections of unmodified lines. Feedback focused on simplifying the context collapsing logic by removing redundant checks and improving safety with saturating_sub for line count calculations.

Comment thread crates/jj-diff/src/context.rs Outdated
Comment thread crates/jj-diff/src/context.rs Outdated
@hewigovens hewigovens changed the title perf(jj-diff): keep short context runs uncollapsed feat(diff): context collapse threshold + word wrap May 21, 2026
@hewigovens hewigovens force-pushed the perf/jj-diff-context-threshold branch 3 times, most recently from 5337a75 to 8de0f94 Compare May 21, 2026 23:37
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