Skip to content

Add mouse support - #142

Merged
umputun merged 15 commits into
masterfrom
mouse-support
Apr 22, 2026
Merged

umputun merged 15 commits into
masterfrom
mouse-support

Conversation

@umputun

@umputun umputun commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Adds mouse support with scroll-wheel in both panes and left-click for tree/diff navigation.

Added

  • scroll-wheel in diff and tree (routed by pane under the pointer, not current focus)
  • shift+wheel scrolls half-page
  • left-click on tree entry selects and loads that file
  • left-click on diff line sets cursor (click then a to annotate that line)
  • --no-mouse / REVDIFF_NO_MOUSE opt-out for users who prefer terminal-native text selection

Text selection

Once mouse tracking is on, plain drag is captured. Users hold Shift (most terminals) or Option (iTerm2) to select. The tree pane sits on the same rows as the diff, so multi-line drags will pick up tree content. For clean diff copies, use terminal block-select (iTerm2 Option+drag, kitty Ctrl+Shift+drag) or run with --no-mouse.

Out of scope

Clickable status-bar segments, overlay item clicks, right-click menus, drag-selection, middle-click paste. Kept for a future follow-up if the need shows up.

Docs

README, site/docs.html, docs/ARCHITECTURE.md, and both Claude and Codex plugin references updated.

umputun added 14 commits April 22, 2026 12:54
Adds the NoMouse option (CLI flag, env var, ini) following the existing
no-* flag pattern. When not set, tea.WithMouseCellMotion() is appended
to program options so future handleMouse work can observe wheel and
click events. Defaults preserve current behavior modulo mouse tracking,
which will start flowing through Update() once the handler lands.
Inverse of cursorVisualRange: given a visual row within the diff viewport
content, returns the diff-line index and whether the row lies on an
injected annotation sub-line. Handles file-level annotations (idx=-1),
wrapped rows, collapsed-mode hidden lines, and out-of-bounds rows.

Foundation for mouse click-to-cursor in the diff pane.
Maps a visible screen row (0-based from the first rendered line)
to an entry index via the pane's internal offset, returning false
for out-of-bounds rows without touching the cursor.

Unlocks click-to-select once the mouse handler arrives.
Introduce hitZone classification (hitNone/hitTree/hitDiff/hitStatus/hitHeader)
with Model.hitTest(x, y) dispatching screen coordinates to the right pane.
Add statusBarHeight, diffTopRow, treeTopRow methods as the single source of
truth for layout math. Tree block spans treeWidth+2 columns (including
borders), diff picks up at treeWidth+2.
Wire bubbletea mouse events into the Model via a new tea.MouseMsg case in
Update. handleMouse clears transient hints, swallows input during modal
states (annotating, searching, pending reload, confirm discard, overlay
open), and dispatches on button:

- wheel up/down: routes to pane under the pointer (not the focused pane).
  Shift+wheel scrolls by half the diff viewport; plain wheel uses
  wheelStep=3.
- wheel left/right: intentionally swallowed; horizontal scroll stays
  keyboard-driven.
- left press: clickTree selects and loads the entry under the pointer
  (mirrors j-to-land behavior, reusing loadSelectedIfChanged); clickDiff
  moves the diff cursor to the visual row using visualRowToDiffLine,
  preserving cursorOnAnnotation when the row falls on an annotation
  sub-line.
- other buttons, release, and motion: no-op.

Extends FileTreeComponent and TOCComponent interfaces with
SelectByVisibleRow so the click helpers can map screen rows to entries
without importing sidepane concretes into mouse.go.
Move plan to docs/plans/completed/ and mark Task 9 wrap-up items as done.
Skipped CLAUDE.md gotcha update — mouse coordinate math is encapsulated in
diffTopRow/treeTopRow/hitTest helpers with explanatory comments, so no
additional note is warranted.
- clickDiff now no-ops when no file is loaded, matching the togglePane
  invariant that paneDiff focus requires m.file.name != "". Previously a
  click before filesLoadedMsg arrived could leave focus on an empty pane.
- handleWheel drops else-if chains in favor of a switch on delta sign and
  a single motion lookup, aligning with the project style rule against
  else-if.
- adds a unit test pinning the no-file clickDiff no-op behavior.
- drop unused x parameter from clickTree and clickDiff, they only
  dispatch by row
- collapse duplicated sign branching in handleWheel tree case into
  a single direction decision
add TOC-sync regression tests for mouse-driven diff navigation so wheel
and click events keep mdTOC.activeSection aligned with the diff cursor
in single-file markdown mode.
Copilot AI review requested due to automatic review settings April 22, 2026 19:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end mouse interaction support to the Bubble Tea TUI, including wheel scrolling routed by pointer position and left-click navigation in both the file tree/TOC and diff pane, with a --no-mouse opt-out.

Changes:

  • Enable Bubble Tea mouse tracking by default (with --no-mouse / REVDIFF_NO_MOUSE / config opt-out) and add mouse event handling in the UI update loop.
  • Implement mouse hit-testing + routing (wheel + left-click) and add inverse mapping from visual rows to diff-line indices for precise click-to-cursor behavior.
  • Sync documentation across README, site docs, architecture notes, and plugin reference docs; bump Claude plugin version metadata.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/main.go Enables tea.WithMouseCellMotion() unless --no-mouse is set.
app/config.go Adds NoMouse option with CLI/env/ini wiring.
app/config_test.go Adds coverage for --no-mouse parsing and dump-config output.
app/ui/model.go Routes tea.MouseMsg events into the model via handleMouse.
app/ui/mouse.go New mouse routing: hit-testing, wheel/click dispatch, focus updates, and pane-specific behavior.
app/ui/mouse_test.go New unit tests covering hit-testing, wheel/click routing, modal swallowing, and TOC syncing.
app/ui/annotate.go Adds visualRowToDiffLine inverse mapping and annotation-subrow detection helpers.
app/ui/annotate_test.go Adds extensive tests for the inverse visual-row mapping across modes and edge cases.
app/ui/sidepane/filetree.go Adds SelectByVisibleRow for click-based selection.
app/ui/sidepane/filetree_test.go Tests SelectByVisibleRow behavior and edge cases.
app/ui/sidepane/toc.go Adds SelectByVisibleRow for TOC click selection.
app/ui/sidepane/toc_test.go Tests TOC SelectByVisibleRow behavior and edge cases.
README.md Documents mouse behavior, selection trade-offs, and --no-mouse.
site/docs.html Mirrors README mouse section and adds --no-mouse option docs.
docs/ARCHITECTURE.md Documents the new mouse.go responsibilities in the app/ui layout.
docs/plans/completed/20260422-mouse-support.md Adds the completed implementation plan and testing strategy record.
.claude-plugin/skills/revdiff/references/config.md Adds --no-mouse to plugin config reference.
.claude-plugin/skills/revdiff/references/usage.md Adds mouse usage guidance + text selection trade-off note.
plugins/codex/skills/revdiff/references/config.md Mirrors --no-mouse in Codex plugin config reference.
plugins/codex/skills/revdiff/references/usage.md Mirrors mouse usage guidance in Codex plugin docs.
.claude-plugin/plugin.json Bumps Claude plugin version to 0.8.2.
.claude-plugin/marketplace.json Bumps marketplace version to 0.8.2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/ui/mouse.go
Comment on lines +70 to +84
// tree block spans columns [0, treeWidth+1] when visible: left border +
// treeWidth content columns + right border = treeWidth+2 columns total.
// diff block picks up at column treeWidth+2.
if !m.treePaneHidden() && x < m.layout.treeWidth+2 {
if y < m.treeTopRow() {
return hitNone
}
return hitTree
}

if y < m.diffTopRow() {
return hitHeader
}
return hitDiff
}

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

hitTest treats the diff pane’s top border row (y==0) as hitHeader (because it checks only y < diffTopRow()). This contradicts the hitNone contract (“borders, gaps”) and can become a real behavior bug if header clicks become meaningful later. Consider returning hitNone for y==0 explicitly (and reserving hitHeader for the actual header row y==1).

Copilot uses AI. Check for mistakes.
Comment thread app/ui/mouse.go Outdated
Comment on lines +143 to +151
// wheelStepFor returns the wheel scroll step. Shift+wheel scrolls by half
// the diff viewport (mirroring the half-page-down keyboard shortcut);
// a plain wheel notch scrolls by the wheelStep constant.
func (m Model) wheelStepFor(shift bool) int {
if shift {
return max(1, m.layout.viewport.Height/2)
}
return wheelStep
}

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

Shift+wheel uses m.layout.viewport.Height/2 via wheelStepFor, even when the pointer is over the tree/TOC pane. Keyboard half-page in the tree/TOC uses treePageSize()/2, so shift+wheel can scroll a slightly different amount than the equivalent keybinding. Consider computing the half-page step based on the target hit zone (diff: viewport height; tree/TOC: treePageSize) to keep behaviors consistent.

Copilot uses AI. Check for mistakes.
Comment thread app/ui/mouse.go
Comment on lines +116 to +120
case tea.MouseButtonWheelUp:
return m.handleWheel(zone, -m.wheelStepFor(msg.Shift))
case tea.MouseButtonWheelDown:
return m.handleWheel(zone, m.wheelStepFor(msg.Shift))
case tea.MouseButtonWheelLeft, tea.MouseButtonWheelRight:

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

Wheel events are handled solely based on msg.Button and will run even if msg.Action isn’t MouseActionPress. Bubble Tea’s own viewport mouse handling guards on msg.Action == MouseActionPress, which prevents accidental double-handling if a terminal/driver ever emits non-press wheel actions. Consider adding the same guard for wheel buttons in handleMouse.

Suggested change
case tea.MouseButtonWheelUp:
return m.handleWheel(zone, -m.wheelStepFor(msg.Shift))
case tea.MouseButtonWheelDown:
return m.handleWheel(zone, m.wheelStepFor(msg.Shift))
case tea.MouseButtonWheelLeft, tea.MouseButtonWheelRight:
case tea.MouseButtonWheelUp:
if msg.Action != tea.MouseActionPress {
return m, nil
}
return m.handleWheel(zone, -m.wheelStepFor(msg.Shift))
case tea.MouseButtonWheelDown:
if msg.Action != tea.MouseActionPress {
return m, nil
}
return m.handleWheel(zone, m.wheelStepFor(msg.Shift))
case tea.MouseButtonWheelLeft, tea.MouseButtonWheelRight:
if msg.Action != tea.MouseActionPress {
return m, nil
}

Copilot uses AI. Check for mistakes.
- hitTest: return hitNone for diff pane top border (y==0) instead of
  hitHeader, matching the tree pane symmetry and the hitNone contract
  for borders/gaps.
- wheelStepFor: use treePageSize/2 for shift+wheel over the tree/TOC
  pane so mouse half-page matches the keyboard half-page for that pane,
  instead of viewport.Height/2 (which is the diff half-page).
- handleMouse: guard wheel events on MouseActionPress for symmetry with
  the left-click branch, preventing double-handling if a terminal emits
  non-press wheel events.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Deploying revdiff with  Cloudflare Pages  Cloudflare Pages

Latest commit: 71f297b
Status: ✅  Deploy successful!
Preview URL: https://0f7e21b1.revdiff.pages.dev
Branch Preview URL: https://mouse-support.revdiff.pages.dev

View logs

@umputun
umputun merged commit 10503fd into master Apr 22, 2026
5 checks passed
@umputun
umputun deleted the mouse-support branch April 22, 2026 19:28
umputun added a commit that referenced this pull request Apr 23, 2026
* feat(ui): route mouse wheel through overlay popups

PR #142 left all mouse events swallowed while any overlay was open.
Most visibly, the commit-info popup (i) supports j/k/g/G keyboard
scroll but ignored the wheel.

Wire tea.MouseMsg through the overlay manager when an overlay is
active:
- commitinfo: wheel adjusts offset by 3; shift+wheel by half viewport
- annotlist:  wheel moves cursor by 1; shift+wheel by half page
- themeselect: wheel moves cursor + live preview; shift+wheel by half page
- help: no scrollable state, wheel is a no-op

Clicks inside overlays remain swallowed (follow-up). --no-mouse still
turns everything off, same flag.

* feat(ui): left-click selection in overlay popups

Extend the overlay mouse routing so left-click inside a popup selects
an item, not just wheel-scrolls it.

- annotlist: click on an item row jumps to that annotation (same as
  Enter) and closes the overlay
- themeselect: click on an entry confirms that theme (same as Enter);
  clicks on filter, blank separator, or border/padding are no-ops
- commitinfo / help: no selectable items, clicks are no-ops

Manager records the popup rectangle during Compose and translates
screen coords to popup-local before dispatch, so each overlay reasons
about its own layout. Clicks outside the popup are swallowed rather
than dismissing, to avoid accidental close.

* fix(ui): address code review findings for overlay mouse support

Bug fixes:
- annotlist/themeselect click handlers now check X coordinate against
  the popup width; clicks on the left/right border or horizontal
  padding are no-ops (previously selected items). Fixes accidental
  theme-persist on mis-clicked chrome.
- themeselect click now updates lastPreviewedName so a subsequent
  keyboard-wheel back to the same entry does not re-emit a preview.

Test improvements:
- Strengthen TestModel_HandleMouse_WheelScrollsCommitInfoOverlay to
  park diffCursor at a non-zero value so wheel-leaking-through would
  be visible.
- Add model-level wheel tests for annotlist and themeselect.
- Add model-level click-to-jump and click-to-confirm integration tests.
- Add horizontal-chrome click tests (border/padding columns).
- Add empty-entries click test for themeselect (panic guard).
- Add Close-clears-bounds test.
- Add no-active-overlay HandleMouse test.

Cleanup:
- Consolidate wheel-step constant: export overlay.WheelStep and have
  app/ui.wheelStep reference it (single source of truth).
- Drop unreachable case KindNone in Manager.HandleMouse switch (early
  return already handles it).
- Clarify unreachable Closed/ThemeCanceled branches in
  handleOverlayMouse via comment (kept for keyboard-path symmetry).
- Drop dead _ = i in commitinfo_test.go loop.
- Restore trailing newline in diffnav_test.go (unrelated formatter
  artifact).

Docs:
- CLAUDE.md: add overlay mouse gotcha (HandleMouse, Manager.bounds
  side effect, Close reset, row offsets, shared WheelStep).
- README, site/docs.html, plugin + codex usage.md: clarify help
  overlay ignores all mouse events, not just wheel.

* fix(ui): address Copilot findings on overlay mouse integration tests

Copilot flagged three weaknesses in the click-dispatch tests added in
the prior review-fix commit:

1. TestModel_HandleMouse_ClickConfirmsThemeSelect asserted only
   overlay-close, which Manager.HandleMouse guarantees on
   OutcomeThemeConfirmed before Model dispatch runs — and opening via
   mgr.OpenThemeSelect bypassed Model.openThemeSelector, leaving
   themePreview nil so confirmThemeByName was a silent no-op. Now
   opens via the real Model path, uses the test theme catalog, and
   asserts themePreview cleared + activeThemeName set to the clicked
   entry.

2. TestModel_HandleMouse_ClickJumpsAnnotList had the same weak
   assertion. Now asserts pendingAnnotJump set to the cross-file
   target (b.go, line 1) — the real Model-side effect of
   jumpToAnnotationTarget.

3. Base screen buffer used Repeat("line\n", height) which adds a
   trailing newline and makes strings.Split yield height+1 rows,
   shifting Manager.bounds vs real View() output. Added
   makeOverlayBase helper matching overlay/help_test.go::makeBase
   (join without trailing), used across all affected tests.

Click coordinates are now computed against concrete popup layouts
(themeselect popup spans rows 15-23; annotlist popup spans 15-23 with
5 items) so the tests hit known entry rows deterministically.
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.

2 participants