Skip to content

Commit 5d3157f

Browse files
geevensinghCopilot
andcommitted
Empty-space click on hunk bar recenters viewport on cursor (minimap-style)
Clicking empty bar space — anywhere that's neither a hunk marker nor the viewport band — now snaps the band's center to the cursor and enters a sticky-thumb drag in the same gesture. A quick click jumps the editor to that fraction of the file; press-and-drag continues scrubbing without releasing. Implemented by extending the existing drag path: in OnMouseLeftButtonDown's empty branch (which previously bubbled), set _bandDragOffsetFromTop = bandHeight/2 so the cursor maps to the band's center, transition directly to BarInteractionState.Dragging (skipping PendingClick — we want the scroll to fire on MouseDown, not require a MouseMove), and emit one EmitDragScroll. All downstream behaviour (ghost-band paint, scroll request, MouseUp ending the drag without a JumpToHunk) flows from the existing Dragging state. No new public surface; just the new empty-space branch. If no band exists yet (no file loaded / pre-layout) the click bubbles as before — nothing meaningful to center on. AI-Local-Session: b53d5fe5-38cc-41dd-b987-3def5ef3f0d3 AI-Cloud-Session: 744dd836-01e5-48af-91db-daa8241a01d7 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9130979 commit 5d3157f

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ body. Keep section headings exact and write notes in Markdown.
3636
position on every mouse-move frame instead of waiting for the
3737
editor's scroll + layout pass to round-trip — keeps the indicator
3838
truly stuck to the cursor even on large files where the editor
39-
scroll can't quite keep up at fast drag speeds.
39+
scroll can't quite keep up at fast drag speeds. Clicking empty
40+
bar space (anywhere that isn't a hunk marker or the viewport
41+
indicator) recenters the indicator on the cursor and starts a
42+
drag in the same gesture — minimap-style "click anywhere to jump
43+
there", and a press-and-drag from empty space scrubs without
44+
needing a second click.
4045
- Language-aware syntax highlighting for TypeScript (`.ts`, `.tsx`),
4146
YAML (`.yaml`, `.yml`), Go (`.go`), Rust (`.rs`), Ruby (`.rb`),
4247
Bash / shell (`.sh`, `.bash`, `.zsh`), and TOML (`.toml`). Combined

DiffViewer/Rendering/HunkOverviewBar.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ namespace DiffViewer.Rendering;
2525
/// <item>Hover tooltip shows the hunk's old- and new-side line ranges so
2626
/// the user can scan without clicking. Clicking a marker (or the ribbon
2727
/// between two markers) jumps the editors to that hunk via
28-
/// <see cref="DiffPaneViewModel.JumpToHunk"/>.</item>
28+
/// <see cref="DiffPaneViewModel.JumpToHunk"/>. Clicking empty bar space
29+
/// recenters the viewport band on the cursor (minimap-style "jump to
30+
/// here") and immediately enters a sticky-thumb drag so the same press
31+
/// can continue scrubbing without releasing the button.</item>
2932
/// <item>Cluster markers, popups, and keyboard focus are listed in the
3033
/// plan but deferred to a follow-up — the hit-test still falls through
3134
/// to the nearest marker when two rects overlap.</item>
@@ -359,8 +362,30 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
359362
_vm.Viewport, leftTotal, rightTotal, ActualWidth, ActualHeight, ColumnWidth);
360363
bool inBand = band is not null && HunkOverviewBarGeometry.IsInsideBand(band, p);
361364

362-
// Empty press — let it bubble.
363-
if (idx < 0 && !inBand) return;
365+
// Empty press: minimap-style "click anywhere to jump there".
366+
// The band's center snaps to the cursor immediately, then any
367+
// continued motion drags from there — empty-space press and
368+
// empty-space-press-then-drag are the same gesture, sharing
369+
// the existing sticky-thumb path. Skipping PendingClick and
370+
// going straight to Dragging means the first scroll fires on
371+
// MouseDown (so a quick click lands the band on the cursor
372+
// even without any mouse movement). If there's no band yet
373+
// (no file loaded / pre-layout) we bubble instead — nothing
374+
// to center on.
375+
if (idx < 0 && !inBand)
376+
{
377+
if (band is null) return;
378+
_bandDragOffsetFromTop = HunkOverviewBarGeometry.GetBandHeight(band) / 2.0;
379+
_interactionStartPoint = p;
380+
_pendingHunkIndex = -1;
381+
_bandWasUnderClick = false;
382+
_interaction = BarInteractionState.Dragging;
383+
ToolTip = null;
384+
CaptureMouse();
385+
EmitDragScroll(p);
386+
e.Handled = true;
387+
return;
388+
}
364389

365390
// Defer both the JumpToHunk commit and the drag start to
366391
// MouseMove/MouseUp so a click that lands on a hunk marker

0 commit comments

Comments
 (0)