Skip to content

Mouse wheel and click support in overlay popups - #144

Merged
umputun merged 4 commits into
masterfrom
feat/overlay-mouse-support
Apr 23, 2026
Merged

umputun merged 4 commits into
masterfrom
feat/overlay-mouse-support

Conversation

@umputun

@umputun umputun commented Apr 23, 2026

Copy link
Copy Markdown
Owner

Context

PR #142 shipped mouse support but swallowed every event while any overlay was open. The commit-info popup has j/k/g/G/PageDown keyboard scrolling but the wheel did nothing — reported in conversation and confirmed in app/ui/mouse.go where m.overlay.Active() unconditionally returned early. This branch extends the overlay manager to accept wheel and left-click events, and keeps the --no-mouse opt-out as the single flag controlling all mouse behavior.

What changed

Wheel (83a2de4)

  • overlay.Manager.HandleMouse mirrors HandleKey: routes wheel to the active overlay, applies the same auto-close rules
  • commit-info scrolls by WheelStep (3) lines per notch; shift+wheel by half-viewport
  • annotlist / themeselect move their cursor one entry per notch; shift+wheel by half-page; themeselect emits OutcomeThemePreview for live preview
  • help has no scrollable state — wheel is a no-op
  • app/ui/mouse.go::handleOverlayMouse delegates when overlay is active and dispatches outcomes through the same helpers as keyboard

Click (661d180)

  • Manager.bounds records the popup rectangle during Compose(); HandleMouse translates screen coords to popup-local before dispatch
  • Left-click on an annotlist item row jumps to that annotation (same as Enter)
  • Left-click on a themeselect entry row confirms that theme (same as Enter)
  • Clicks outside the popup rectangle are swallowed — overlays stay open, dismiss with Esc
  • commit-info and help ignore clicks (no selectable items)

Review fixes (44aa25a)

  • Click handlers now hit-test X as well as Y; clicks on the left/right border and horizontal padding are no-ops (previously selected items — could accidentally persist a theme on a mis-click)
  • themeselect click updates lastPreviewedName so a later keyboard nav back to the same entry does not re-emit a redundant preview
  • Commit-info wheel test strengthened (parks diffCursor mid-stream to catch wheel-leakage)
  • Added model-level tests for annotlist/themeselect wheel + click-to-select integration
  • Consolidated WheelStep (exported from overlay, referenced from app/ui)
  • Docs: CLAUDE.md overlay-mouse gotcha, README/site/plugin/codex usage synced

Opt-out

--no-mouse / REVDIFF_NO_MOUSE=true / no-mouse = true in config still turns everything off — tea.WithMouseCellMotion() is the single switch, so bubbletea never emits mouse events and none of the new handlers run.

umputun added 3 commits April 23, 2026 02:31
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.
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.
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.
Copilot AI review requested due to automatic review settings April 23, 2026 08:04

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 mouse-wheel scrolling and left-click selection support to overlay popups (help / commit-info / annotation list / theme selector) by extending the overlay manager with HandleMouse and routing overlay mouse events through the Model, while keeping --no-mouse as the single opt-out.

Changes:

  • Introduce overlay.Manager.HandleMouse with popup hit-testing via composed bounds and per-overlay wheel/click handling.
  • Implement wheel + click behavior for annotlist/themeselect/commitinfo/help overlays and route resulting outcomes through app/ui (theme preview/confirm, annotation jump).
  • Expand tests and update docs (README/site/docs/plugins/ARCHITECTURE/CLAUDE) to reflect new overlay mouse behavior.

Reviewed changes

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

Show a summary per file
File Description
site/docs.html Document wheel/click behavior for overlay popups and click-outside swallowing.
plugins/codex/skills/revdiff/references/usage.md Sync Codex plugin usage docs with overlay mouse behavior.
docs/ARCHITECTURE.md Update overlay manager interface/behavior documentation to include mouse routing.
app/ui/overlay/themeselect_test.go Add wheel + click unit/integration tests for theme selector overlay.
app/ui/overlay/themeselect.go Add mouse handling, cursor movement helper, and click hit-testing for theme selector.
app/ui/overlay/overlay_test.go Add tests for HandleMouse no-overlay behavior and bounds reset on Close.
app/ui/overlay/overlay.go Add bounds tracking, HandleMouse, and coordinate translation for popup-local hit-testing.
app/ui/overlay/help_test.go Add no-op mouse behavior test for help overlay.
app/ui/overlay/help.go Consume mouse events in help overlay (no-op).
app/ui/overlay/commitinfo_test.go Add wheel scrolling tests for commit-info overlay.
app/ui/overlay/commitinfo.go Add wheel scrolling handler and export WheelStep.
app/ui/overlay/annotlist_test.go Add wheel + click tests (including bounds translation) for annotation list overlay.
app/ui/overlay/annotlist.go Add mouse handling, cursor movement helper, and click hit-testing for annotation list.
app/ui/mouse_test.go Add Model-level tests for overlay wheel/click dispatch paths.
app/ui/mouse.go Route mouse events to overlays when active; reuse overlay.WheelStep.
app/ui/model.go Extend overlayManager interface with HandleMouse.
app/ui/diffnav_test.go Remove trailing whitespace line.
README.md Document overlay wheel/click behavior and click-outside swallowing.
CLAUDE.md Add overlay-mouse routing notes and implementation gotchas.
.claude-plugin/skills/revdiff/references/usage.md Sync Claude plugin usage docs with overlay mouse behavior.

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

Comment thread app/ui/mouse_test.go Outdated
Comment on lines +695 to +713
mgr.OpenThemeSelect(overlay.ThemeSelectSpec{Items: []overlay.ThemeItem{
{Name: "a"}, {Name: "b"},
}, ActiveName: "a"})
// prime bounds via Compose so Manager.HandleMouse can translate screen to popup-local
ctx := overlay.RenderCtx{Width: m.layout.width, Height: m.layout.height, Resolver: m.resolver}
base := strings.Repeat(strings.Repeat(" ", m.layout.width)+"\n", m.layout.height)
_ = mgr.Compose(base, ctx)

// we need the popup's screen coords — derive from the manager by reading bounds
// via the same Compose output. Since we can't read Manager.bounds from outside the
// overlay package, the simplest verification: send a click at the screen center
// (popup is centered by Compose) and verify the outcome path runs. The actual
// row math is exercised by overlay-package tests; here we verify the Model-side
// side-effect pathway (confirmThemeByName is invoked and overlay closes).
centerX, centerY := m.layout.width/2, m.layout.height/2
result, _ := m.Update(leftPressAt(centerX, centerY))
model := result.(Model)

assert.False(t, model.overlay.Active(), "click inside popup on an entry row should confirm and close the overlay")

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

This test currently only asserts that the overlay closes after a center-screen click. Since overlay.Manager.HandleMouse auto-closes on OutcomeThemeConfirmed before Model dispatch runs, the assertion can pass even if Model stops handling OutcomeThemeConfirmed entirely. Also, opening the overlay directly via mgr.OpenThemeSelect bypasses Model.openThemeSelector, so m.themePreview is nil and confirmThemeByName becomes a no-op. To actually cover the Model-side integration, initialize the theme preview session (or open the selector through the Model) and assert a side effect (e.g., theme persisted/activeThemeName changed, or resolver/style updated).

Copilot uses AI. Check for mistakes.
Comment thread app/ui/mouse_test.go Outdated
Comment on lines +733 to +737
// hits the first item row. verifies Manager.HandleMouse → annotlist → jump path.
centerX, centerY := m.layout.width/2, m.layout.height/2
result, _ := m.Update(leftPressAt(centerX, centerY))
model := result.(Model)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

Similar to the theme click test above, this only asserts that the overlay closes after a center-screen click. Because overlay.Manager.HandleMouse auto-closes on OutcomeAnnotationChosen, the test can pass even if Model stops dispatching OutcomeAnnotationChosen to jumpToAnnotationTarget. Consider asserting an observable Model-side effect (e.g., pendingAnnotJump set/cleared, selected file changed to b.go, diff cursor repositioned) so this test actually validates the end-to-end click→jump integration.

Suggested change
// hits the first item row. verifies Manager.HandleMouse → annotlist → jump path.
centerX, centerY := m.layout.width/2, m.layout.height/2
result, _ := m.Update(leftPressAt(centerX, centerY))
model := result.(Model)
// hits the first item row. This must validate the end-to-end integration:
// Manager.HandleMouse chooses the annotation, Model dispatches the outcome to
// the jump handler, the selected file changes to the annotation target, and
// the overlay then closes.
centerX, centerY := m.layout.width/2, m.layout.height/2
result, _ := m.Update(leftPressAt(centerX, centerY))
model := result.(Model)
assert.Equal(t, "b.go", model.selectedFile, "click on item row should jump to the annotation target file")

Copilot uses AI. Check for mistakes.
Comment thread app/ui/mouse_test.go Outdated
Comment on lines +699 to +701
ctx := overlay.RenderCtx{Width: m.layout.width, Height: m.layout.height, Resolver: m.resolver}
base := strings.Repeat(strings.Repeat(" ", m.layout.width)+"\n", m.layout.height)
_ = mgr.Compose(base, ctx)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

The base screen buffer here is built with a trailing newline (Repeat("line\n", height)), which makes strings.Split(bg, "\n") produce an extra empty row. Since overlay.Manager.overlayCenter uses len(bgLines) for centering/bounds, this test setup can shift mgr.bounds compared to the real View() output (which is joined without a trailing newline), making click hit-testing more brittle. Consider using the same pattern as overlay tests (join height lines without a trailing newline) when priming bounds.

Copilot uses AI. Check for mistakes.
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.
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying revdiff with  Cloudflare Pages  Cloudflare Pages

Latest commit: 020dcb2
Status: ✅  Deploy successful!
Preview URL: https://bd0c73e3.revdiff.pages.dev
Branch Preview URL: https://feat-overlay-mouse-support.revdiff.pages.dev

View logs

@umputun
umputun merged commit 6152369 into master Apr 23, 2026
5 checks passed
@umputun
umputun deleted the feat/overlay-mouse-support branch April 23, 2026 08:20
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