refactor(desktop): port v2 DiffPane to @pierre/diffs CodeView

Merged
KI
6mo ago
+1007-871

Summary

  • Upgrade @pierre/diffs to 1.2.2 and replace the custom Virtualizer + DOM-querying scroll glue (ScrollToFile / findLineElement / data-diff-path selectors) with the new CodeView API. scrollTo({ type: "line", side }) now drives jump-to-comment, including LEFT vs RIGHT side disambiguation so a deletion-side comment lands on the deletion line.
  • Split per-file useDiffAnnotations into a single useDiffAnnotationsByPath query so CodeView can render every file's annotations from one source.
  • Delete DiffFileEntry / WorkspaceDiff / useInView and the expandedFiles lazy-load plumbing — CodeView handles virtualization itself.

DiffFocusSide is threaded from the comments list (CommentsSection → useReviewTab → WorkspaceSidebar) through openDiffPane into DiffPaneData.focusSide, then consumed by the scroll effect.

Test plan

  • Open a workspace with a PR. Click a review comment in the sidebar Review tab — diff opens and scrolls to the commented line; LEFT comments land on the deletion side, RIGHT comments on the addition side.
  • Click the same comment again — diff re-scrolls (focus tick bumps).
  • "Open in new diff tab" from a comment row works.
  • Toggle "Show comments in diff" off — comment annotations disappear; re-enable and they come back.
  • Toggle "Expand unchanged lines" in the per-file header.
  • Collapse / re-expand a file via the header; mark viewed; discard unstaged changes via the menu.
  • Open a workspace with no PR — no stale annotations leak through.
  • Renamed file: comment anchored on the old path still surfaces in the diff.

Open in Stage

Summary by cubic

Ported the v2 DiffPane to @pierre/diffs CodeView for simpler rendering, side-aware jump-to-comment, and built-in virtualization with sticky headers. Added header slots, caps for huge files, a pane-wide persisted expand-unchanged toggle, small a11y fixes, and a follow-ups plan for gutter utility and line selection.

  • Refactors

    • Upgraded @pierre/diffs to 1.2.2 and replaced the custom Virtualizer + DOM querying with CodeView.
    • Added useDiffCodeViewItems, useDiffCodeViewScroll, and useDiffCodeViewTheme; consolidated annotations into useDiffAnnotationsByPath with rename support.
    • Introduced DiffHeaderPrefix and DiffHeaderMetadata; CodeView now handles virtualization and sticky headers.
    • Threaded DiffFocusSide from comments to diff; scrollTo({ type: "line", side }) lands on the correct side.
    • Capped tokenizeMaxLineLength, tokenizeMaxLength, and maxLineDiffLength; removed redundant CodeView config and deleted DiffFileEntry, WorkspaceDiff, useInView, and expandedFiles plumbing.
    • Moved “Expand unchanged” to the pane header via DiffPaneHeaderExtras and persisted it as useSettings.expandUnchanged; revealed Discard on focus and made loading/error text copyable.
  • Migration

    • onOpenInDiff(path, line?, openInNewTab?, side?) now takes side?: DiffFocusSide.
    • DiffPaneData adds focusSide and removes expandedFiles.

Summary by CodeRabbit

  • New Features

    • Review comments can now open diffs focused on the correct side (additions or deletions).
    • New "Show unchanged regions" toggle and preference to control whether unchanged lines are expanded.
  • Improvements

    • Redesigned diff viewer for smoother scrolling, faster rendering, and more reliable file-focused navigation.
    • Enhanced per-file header controls: viewed flag, expand/collapse toggle, copy-path and discard actions.
  • Documentation

    • Added follow-up notes outlining future diff-pane enhancements and QA items.

Review Change Stack