Skip to content

feat(diff-comments): add multi-line range selection with drag and keyboard - #20959

Merged
AmethystLiang merged 4 commits into
mainfrom
multi-select-ai-annotation
Sep 19, 2026
Merged

AmethystLiang merged 4 commits into
mainfrom
multi-select-ai-annotation

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1475 $\color{#cf222e}{\Huge{\mathbf{−}}}$​66 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1409
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​923 $\color{#cf222e}{\Huge{\mathbf{−}}}$​133 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​790

Problem

Diff comments were limited to single lines, matching only basic review tools. Modern code review requires selecting ranges to comment on related logic.

Solution

Added multi-line range selection via two gestures:

  1. Gutter drag: Press and drag down the line numbers to select a range; the selection stays lit while the note opens
  2. Keyboard shortcut: Shift+Arrow to select in the editor, then Mod+Shift+A to open a ranged note

The implementation:

  • Captures pointer events on the gutter before Monaco's handler, using a probe column (not the pointer's own column) to hit-test continuously without Monaco's dead zone over the overlay button
  • Animates auto-scroll when the drag reaches viewport edges
  • Clamps the range to hunk boundaries (commentable-line set)
  • Keeps the selection band lit while the composer is open
  • Treats single-line selections identically to existing clicks (wire shape unchanged)

Visual Proof

  • TODO: Add before/after video of gutter drag selecting lines 4–9, button following the drag end, range band persisting while note is written
  • TODO: Add screenshot of keyboard flow: selection → Mod+Shift+A → "Lines X–Y" label in composer

Testing

  • E2E tests added: tests/e2e/diff-note-line-range.spec.ts covers gutter drag, button drag, single-line click, Escape abort, and keyboard chord
  • Unit tests added for drag physics, line-range arithmetic, and auto-scroll timing
  • Monaco integration tested with fake editor fixture (decorations, hit-test zones, scroll position)
  • Manual test: gutter drag on real diff; keyboard flow on single and multi-line selections

Linked Issue

Fixes #

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security (pointer capture released properly), Cross-platform support (keyboard shortcuts tested on Mac/Linux/Windows with correct modifiers), Remote SSH (gutter gesture over SSH terminal-rendered diffs), Mobile (touch ignored; pane scrolling preserved), backward compatibility (single-line notes wire-identical to before).

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1ee8007d-0a5a-41b5-af8e-baf41a100b18

📥 Commits

Reviewing files that changed from the base of the PR and between ed5b917 and f3430b1.

📒 Files selected for processing (21)
  • src/renderer/src/assets/main.css
  • src/renderer/src/components/diff-comments/diff-comment-add-button-overlay.ts
  • src/renderer/src/components/diff-comments/diff-comment-add-note-shortcut.ts
  • src/renderer/src/components/diff-comments/diff-comment-drag-auto-scroll.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-drag-auto-scroll.ts
  • src/renderer/src/components/diff-comments/diff-comment-editor-test-fixture.ts
  • src/renderer/src/components/diff-comments/diff-comment-line-range.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-line-range.ts
  • src/renderer/src/components/diff-comments/diff-comment-range-drag.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-range-drag.ts
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.commentable-lines.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.model-lifecycle.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.range-selection.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.tsx
  • src/renderer/src/components/editor/DiffSectionBody.tsx
  • src/renderer/src/components/editor/DiffSectionItem.tsx
  • src/renderer/src/components/editor/DiffViewer.tsx
  • src/renderer/src/components/editor/MonacoMarkdownAnnotationOverlay.tsx
  • src/renderer/src/components/editor/monaco-markdown-selection-annotation.ts
  • src/renderer/src/components/editor/use-monaco-markdown-annotations.ts
  • tests/e2e/diff-note-line-range.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/assets/main.css

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds ranged diff comments. Shared helpers normalize line ranges and selections. A drag controller supports gutter selection, hunk-boundary clamping, auto-scroll, cancellation, and decorations. The add-button overlay and decorator use the controller. The Add Review Note shortcut opens single-line or ranged composers. Popover keys include both line bounds. CSS and unit, component, and end-to-end tests cover the new behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to f3430

No concrete correctness or usability issue remains from the reviewed range-selection changes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, implementation, and automated tests, but required information is incomplete. The linked issue is missing, visual proof is still marked TODO, manual test… Add the issue number after "Fixes #". Attach the required before/after video and keyboard-flow screenshot. Document manual testing and tested platforms. Complete the ELI5, Why, AI Disclosure if applicable, Review, Notes, and remaining check…
Docstring Coverage ⚠️ Warning Docstring coverage is 27.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 20 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: multi-line diff-comment range selection through drag and keyboard input.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, solution, implementation, and automated tests, but required information is incomplete. The linked issue is missing, visual proof is still marked TODO, manual testing is unchecked, and several checklist and template sections are incomplete.

Resolution

Add the issue number after "Fixes #". Attach the required before/after video and keyboard-flow screenshot. Document manual testing and tested platforms. Complete the ELI5, Why, AI Disclosure if applicable, Review, Notes, and remaining checklist items, including command and CI status.

Full details: Docstring Coverage

Explanation

Docstring coverage is 27.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 20 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1527024b-cd56-4fdd-9f55-e358de0dda10

📥 Commits

Reviewing files that changed from the base of the PR and between 47bb473 and edd67b6.

📒 Files selected for processing (21)
  • src/renderer/src/assets/main.css
  • src/renderer/src/components/diff-comments/diff-comment-add-button-overlay.ts
  • src/renderer/src/components/diff-comments/diff-comment-add-note-shortcut.ts
  • src/renderer/src/components/diff-comments/diff-comment-drag-auto-scroll.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-drag-auto-scroll.ts
  • src/renderer/src/components/diff-comments/diff-comment-editor-test-fixture.ts
  • src/renderer/src/components/diff-comments/diff-comment-line-range.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-line-range.ts
  • src/renderer/src/components/diff-comments/diff-comment-range-drag.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-range-drag.ts
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.commentable-lines.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.model-lifecycle.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.range-selection.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.tsx
  • src/renderer/src/components/editor/DiffSectionBody.tsx
  • src/renderer/src/components/editor/DiffSectionItem.tsx
  • src/renderer/src/components/editor/DiffViewer.tsx
  • src/renderer/src/components/editor/MonacoMarkdownAnnotationOverlay.tsx
  • src/renderer/src/components/editor/monaco-markdown-selection-annotation.ts
  • src/renderer/src/components/editor/use-monaco-markdown-annotations.ts
  • tests/e2e/diff-note-line-range.spec.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The gutter drag is installed on every surface that uses the decorator, not just diffs, and it claims more of the gutter than the gesture needs. On the markdown annotations editor it swallows Monaco's fold chevrons (and turns line-number presses into comment gestures). Narrowing the intercepted target types keeps the drag while leaving stock Monaco gestures intact.

Reviewed changes

  • New range helpers (diff-comment-line-range.ts): ordering/clamping/selection math shared by the drag, the chord and the markdown path, with startLine omitted for single lines so the stored shape is unchanged.
  • Gutter drag controller (diff-comment-range-drag.ts + diff-comment-drag-auto-scroll.ts): pointer-capture drag, per-frame hit-test against a fixed probe column, edge auto-scroll, hunk clamping, Escape/pointercancel abort.
  • Overlay/decorator wiring (diff-comment-add-button-overlay.ts, useDiffCommentDecorator.tsx): the overlay owns the drag and exposes setPendingRange; the decorator threads pendingCommentTarget so the band stays lit under the open composer.
  • Keyboard chord (diff-comment-add-note-shortcut.ts): editor.addReviewNote opens a ranged composer from the editor selection; popover keys now include startLine.
  • Tests: unit suites for range math, drag physics, auto-scroll and decorator range/chord/drag, plus tests/e2e/diff-note-line-range.spec.ts.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@AmethystLiang
AmethystLiang force-pushed the multi-select-ai-annotation branch from edd67b6 to 5c61b28 Compare September 16, 2026 05:57

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The e2e / changed e2e specs check is red on this head — every test in tests/e2e/diff-note-line-range.spec.ts fails at gutterPoint with line N is not rendered in the modified gutter, identically to the prior commit's run. This commit's helper rewrite does not address the cause, and the upward-drag test added here is among the failures.

Reviewed changes

  • Gutter press narrowed to line numbers (diff-comment-range-drag.ts): GUTTER_PRESS_TARGET_TYPES drops GUTTER_GLYPH_MARGIN and GUTTER_LINE_DECORATIONS, so fold chevrons and glyph-margin presses reach Monaco while the + press still resolves through the button (plus.contains, not a Monaco target).
  • Directional selection clamping (diff-comment-line-range.ts, diff-comment-add-note-shortcut.ts): the new getSelectionAnchorFocus reads Monaco's anchor/active endpoints, so the chord clamps an upward selection from the line it was anchored on instead of the hunk above.
  • Drag state exposed to keyboard paths (diff-comment-range-drag.ts, diff-comment-add-button-overlay.ts, useDiffCommentDecorator.tsx): isDragging() is OR-ed into isComposerOpen, so a chord pressed mid-drag is consumed rather than opening a composer on the stale editor selection.
  • Tests: unit coverage for the anchor/focus direction, the narrow gutter target set, and isDragging; a new upward-drag e2e case (currently failing on CI).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread tests/e2e/diff-note-line-range.spec.ts Resolved
@AmethystLiang
AmethystLiang force-pushed the multi-select-ai-annotation branch from 5c61b28 to ed5b917 Compare September 16, 2026 07:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/renderer/src/components/diff-comments/diff-comment-editor-test-fixture.ts (1)

91-91: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Return a stable model reference from the fixture.

getModel() allocates a new object on every call. Monaco returns the same ITextModel reference until the model is replaced, and the decorator suites key model-lifecycle behavior on that identity. With a new object per call, a model-swap path can appear to run on every render, so useDiffCommentDecorator.model-lifecycle.test.tsx may assert against fixture behavior rather than editor behavior.

Hoist one object. setLineCount keeps working because the getter closes over lineCount.

♻️ Proposed fix
   const noopDisposable: IDisposable = { dispose: () => {} }
+  // Monaco hands back the same model reference until the model is replaced.
+  const model = { getLineCount: () => lineCount }
-    getModel: () => ({ getLineCount: () => lineCount }),
+    getModel: () => model,

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 32cd1dd1-c5fc-4d2f-85ca-b8c76145246d

📥 Commits

Reviewing files that changed from the base of the PR and between 5c61b28 and ed5b917.

📒 Files selected for processing (21)
  • src/renderer/src/assets/main.css
  • src/renderer/src/components/diff-comments/diff-comment-add-button-overlay.ts
  • src/renderer/src/components/diff-comments/diff-comment-add-note-shortcut.ts
  • src/renderer/src/components/diff-comments/diff-comment-drag-auto-scroll.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-drag-auto-scroll.ts
  • src/renderer/src/components/diff-comments/diff-comment-editor-test-fixture.ts
  • src/renderer/src/components/diff-comments/diff-comment-line-range.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-line-range.ts
  • src/renderer/src/components/diff-comments/diff-comment-range-drag.test.ts
  • src/renderer/src/components/diff-comments/diff-comment-range-drag.ts
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.commentable-lines.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.model-lifecycle.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.range-selection.test.tsx
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.tsx
  • src/renderer/src/components/editor/DiffSectionBody.tsx
  • src/renderer/src/components/editor/DiffSectionItem.tsx
  • src/renderer/src/components/editor/DiffViewer.tsx
  • src/renderer/src/components/editor/MonacoMarkdownAnnotationOverlay.tsx
  • src/renderer/src/components/editor/monaco-markdown-selection-annotation.ts
  • src/renderer/src/components/editor/use-monaco-markdown-annotations.ts
  • tests/e2e/diff-note-line-range.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.model-lifecycle.test.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • E2E seed now commits a tracked baseline (tests/e2e/diff-note-line-range.spec.ts): seedDiffFile writes the baseline through Node fs, commits it when the path is dirty, then rewrites the 24-line working tree on top — so the file is an unstaged modification of a tracked file rather than an untracked file whose inline diff opens with no gutter lines.
  • Readiness gate replaced with a poll: the seed waits on the new hasGutterLine(page, 9) for the modified model to render its later gutter lines before any gutterPoint call, removing the race the prior review flagged.

Verified locally with CI=1 SKIP_BUILD=1 ORCA_E2E_HEADLESS=1 ORCA_BACKGROUND_LAUNCH=1 xvfb-run -a npx playwright test --config tests/playwright.config.ts --project=electron-headless tests/e2e/diff-note-line-range.spec.ts → all 6 tests pass, and the e2e / changed e2e specs check is green on this head.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@AmethystLiang
AmethystLiang force-pushed the multi-select-ai-annotation branch from ed5b917 to f3430b1 Compare September 17, 2026 04:27

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Re-reviewed the delta since the prior pullfrog review on ed5b917 (the branch was rebased onto main, so the range-diff isolates the semantic change): a gutter-drag release fix plus test and e2e-helper hardening.

  • Release coordinate captured on pointerup (diff-comment-range-drag.ts): the drag now adopts event.clientY and resolves the focus line before committing, so a release on a line no pointermove ever reported commits the line the user released on instead of a stale one. The coalesced-frame hit-test was extracted into resolveFocusLine, and the final auto-scroll step on release was dropped — correct, since the gesture is over and further scrolling would only push the committed range past the released line.
  • Drag test coverage (diff-comment-range-drag.test.ts): a new case presses and releases across lines with no intervening move; the harness now releases at the pointer's last reported position.
  • Fixture model identity (diff-comment-editor-test-fixture.ts): the fake editor returns one stable model reference, matching Monaco's ITextModel lifetime.
  • E2E gutter lookups hardened (tests/e2e/diff-note-line-range.spec.ts): readGutterPoint is shared, and gutterPoint polls for the target cell instead of throwing on a transient miss.

Verified the three changed unit suites locally (diff-comment-range-drag.test.ts, useDiffCommentDecorator.range-selection.test.tsx, useDiffCommentDecorator.commentable-lines.test.tsx) — 43 tests pass. Typecheck and static analysis are green on f3430b1; the e2e/tests checks were still running at review time.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Enable users to select a range of lines for diff comments by dragging in the gutter, with auto-scroll and visual feedback. Add keyboard shortcut (Mod+Shift+A) to open a comment on the editor selection. Extract line-range logic into testable utilities and add comprehensive test coverage including E2E scenarios.
- Preserve anchor/focus directionality in selections to handle upward drags correctly
- Restrict gutter presses to line numbers only, leaving fold chevrons to Monaco
- Prevent add-note chord from opening composer while a gutter drag is in progress
Pointerup can arrive at a position no pointermove event reported, causing fast drags to lose their final lines if the release landed before the animation frame fired. Capture the release coordinate and resolve it before committing the range.

Also: extract resolveFocusLine for clarity, improve test harness to track pointer position, add polling to gutter detection for rendering delays.
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