Skip to content

fix: let a drag on a diff select text - #68

Merged
handlename merged 2 commits into
mainfrom
fix/copy-on-diff
Aug 29, 2026
Merged

fix: let a drag on a diff select text#68
handlename merged 2 commits into
mainfrom
fix/copy-on-diff

Conversation

@handlename

Copy link
Copy Markdown
Owner

Why this change is necessary

A diff is read by taking lines out of it — into an editor, a terminal, a chat message. On the diff review page that was impossible: dragging across diff lines was consumed as a comment line range, and the composer took focus on mouse-up, so whatever text the drag had selected was gone before it could be copied. There was no other way to get the text out either, short of opening the file the diff came from.

Approach

The drag goes back to the browser. Targeting now runs on mouseup and bails when the selection it finds is not collapsed — the rule the Markdown page has followed all along, so the two review modes now answer the pointer the same way. Comment ranges are made by click and Shift+click, which initializeDiffLines already implemented, so handing the drag back costs nothing.

Shift+click is the exception that rule has to make. The browser extends its own text selection on the way there, and the handler drops that selection before taking the range, because Shift+click is the range gesture and a stray highlight left behind is not what was asked for.

The line number and marker columns are already user-select: none, so what lands on the clipboard is the code alone — no line numbers, no +/-. Nothing had to change for that.

Two alternatives were turned down, and UI_DESIGN.md §5.2 records why: putting text selection behind Option+drag, which preserves every existing habit but hides copying — the more frequent act — behind a modifier no one would guess; and telling the two gestures apart by how far the drag travelled, which has no honest boundary and would flip meaning mid-gesture.

Design Documents

UI_DESIGN.md §5.2 is the design record for this change, and it is updated in this PR rather than kept separately.

Review Points

  • The gesture split is a behaviour change, not only a bug fix. Dragging no longer creates a comment range. Shift+click already existed and covers it, but a reader in the habit of dragging has something to relearn.
  • dragFrom became targetFrom. It is no longer where a drag started; it is the line a Shift+click extends the range from.
  • The verification for this lives outside the Go test suite. UI_DESIGN.md already notes there is no browser test harness here, so this was checked in headless Chrome over CDP: 18 assertions covering drag-to-select, click targeting, Shift+click ranges, file-header drag and click, and the Quote Lines button — plus the whole clipboard path, where a drag across four lines whose markers read " ", " ", "-", "-" copies neither the markers nor the numbers.

handlename and others added 2 commits August 29, 2026 23:01
Targeting ran on mousedown and pulled focus into the composer on
mouseup, so a drag across diff lines was consumed as a line range and
the text selection it made was gone before it could be copied. Reading
a diff means taking lines out of it, so the pointer's own gesture for
that has to keep working.

Targeting now runs on mouseup and bails when the selection it finds is
not collapsed -- the rule the Markdown page has followed all along.
Ranges are made by click and Shift+click, which initializeDiffLines
already implemented, so nothing is lost by handing the drag back. The
mouseover that extended a range while the button was down is gone with
it.

Shift+click is the exception the rule has to make: the browser extends
its own text selection on the way there, and the handler drops that
selection before taking the range, because Shift+click is the range
gesture and a stray highlight is not what was asked for.

The line number and marker columns are already user-select: none, so
what lands on the clipboard is the code alone. Verified in headless
Chrome over CDP, clipboard included: a drag across four lines whose
markers read " ", " ", "-", "-" copies neither the markers nor the
numbers.

User request: diff review 時に document column に表示されている diff の内容をクリップボードにコピーできるようにしたい。
現在はドラッグで範囲選択すると即座に composer がアクティブになり選択状態を維持できず、コピーができない。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
UI_DESIGN 5.2 said "drag or shift-click selects a range" and explained
the mouseup focus as a way to keep click-drag text selection alive.
Both describe the page as it was before the drag was handed back to the
browser.

It now says what the gesture split is and why it falls that way, keeps
the two alternatives that were turned down -- Option+drag, and telling
the two apart by how far the drag travelled -- and notes what the
user-select: none on the number and marker columns buys: the clipboard
gets the code alone, and a drag that starts on a number selects
nothing.

User request: 変更に合わせてドキュメントを追随させる。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

169 tests  ±0   169 ✅ ±0   4s ⏱️ ±0s
  5 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit c4a2b39. ± Comparison against base commit 1ee6201.

@handlename
handlename merged commit 236cf51 into main Aug 29, 2026
2 checks passed
@handlename
handlename deleted the fix/copy-on-diff branch August 29, 2026 14:05
@handlename handlename mentioned this pull request Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant