Skip to content

refactor(editor): move canvas pointer handlers to src/mouse.js (R2, step 34) - #186

Merged
byrongamatos merged 2 commits into
mainfrom
refactor/r2-step34-mouse
Jul 10, 2026
Merged

refactor(editor): move canvas pointer handlers to src/mouse.js (R2, step 34)#186
byrongamatos merged 2 commits into
mainfrom
refactor/r2-step34-mouse

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

What

Step 34 of the R2 module-extraction refactor: move the canvas pointer event handlers out of src/main.js into a new native ES module src/mouse.js.

getMousePos + onMouseDown / onMouseMove / _onMouseMoveBody / onMouseUp / onDblClick / onWheel — the drag/select/inline-edit, double-click-add, and wheel zoom/scroll dispatchers.

How the seam is drawn

The "Mouse interactions" banner is a 2,015-line grab-bag (pointer handlers + keyboard-command layer + tab-preview + shortcut-panel + onContextMenu). This step takes the genuinely-pointer core (595 lines); the rest are separate concerns left in main.js for their own later steps.

  • src/mouse.js: 17 module imports (the pointer core touches most of the graph), 6 handlers exported back — main.js's init() attaches them to the canvas; getMousePos remains a host hook, now sourced here.
  • 4 new host hooks for the composition-root symbols the handlers call: showAddNote, updateZoomDisplay, partsViewOnMouseDown, partsViewOnDblClick.
  • Removed 31 now-dead main.js imports (used only by the moved pointer code) — the strict no-undef gate confirmed no over-removal.
  • tests/keyboard_gutter_dblclick.test.mjs retargeted to slice onDblClick from mouse.js and inject a host stub (onDblClick now reaches showAddNote / partsViewOnDblClick through host).

main.js drops ~595 lines. 35 modules.

Verification

  • 90/90 JS suites pass; ESLint gate clean (0 errors); strict no-undef clean on mouse.js.
  • Codex preflight: 0 correctness issues.
  • New headless harness (verify_mouse.py) drives real pointer events: ctrl+wheel zooms the readout (100→138%, proving host.updateZoomDisplay), clicking a note selects it and reveals the inspector, double-clicking empty grid opens the add-note dialog (proving host.showAddNote), and dragging a note moves it (proving host.draw) — zero page errors. Both new hooks negative-checked.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Expanded canvas interactions with full support for clicking, dragging, rectangular selection, zooming, panning, and mode-aware double-click actions.
    • Enhanced host integration to support showing add-note UI, updating zoom display, and handling Parts-view mouse down/double-click.
  • Bug Fixes
    • Ensured double-click in the keyboard gutter no longer triggers add-note, while double-click in the note area still does.
  • Refactor
    • Consolidated mouse and pointer interaction logic into a dedicated interaction module.
  • Tests
    • Updated the keyboard gutter double-click regression test to match the new interaction path.

…tep 34)

Extract the mouse pointer event handlers (getMousePos + onMouseDown / onMouseMove
/ _onMouseMoveBody / onMouseUp / onDblClick / onWheel — the drag/select/inline-edit,
double-click add, and wheel zoom/scroll dispatchers) out of the src/main.js
monolith into a new native ES module. This is the genuinely-pointer core of the
2,015-line "Mouse interactions" banner; the keyboard-command layer, tab-preview,
shortcut-panel and onContextMenu are separate concerns and stayed in main.js for
their own later steps.

- src/mouse.js: 17 module imports (the pointer core touches most of the graph),
  6 handlers exported back (main.js's init() attaches them to the canvas;
  getMousePos remains a host hook now sourced here).
- 4 new host hooks for the composition-root symbols the handlers call:
  showAddNote, updateZoomDisplay, partsViewOnMouseDown, partsViewOnDblClick.
- Removed 31 now-dead main.js imports (used only by the moved pointer code) — the
  strict no-undef gate confirmed no over-removal.
- tests/keyboard_gutter_dblclick.test.mjs retargeted to slice onDblClick from
  mouse.js and inject a host stub (onDblClick now reaches showAddNote /
  partsViewOnDblClick through host).

main.js drops ~595 lines. 35 modules.

Verified: 90/90 JS suites pass, ESLint gate clean (0 errors), strict no-undef
clean on mouse.js, Codex preflight 0 issues. New headless harness drives REAL
pointer events: ctrl+wheel zooms the readout (proves host.updateZoomDisplay),
clicking a note selects it and reveals the inspector, double-clicking empty grid
opens the add-note dialog (proves host.showAddNote), and dragging a note moves it
(proves host.draw) — zero page errors. Both new hooks negative-checked.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d8168fb-3e45-4de4-8595-f607b454f923

📥 Commits

Reviewing files that changed from the base of the PR and between e480d6e and 7d96355.

📒 Files selected for processing (1)
  • src/mouse.js

📝 Walkthrough

Walkthrough

The PR extracts editor mouse interactions from src/main.js into src/mouse.js, adds host callbacks for note, zoom, and Parts-view interactions, and updates the keyboard-gutter double-click regression test.

Changes

Mouse interaction refactor

Layer / File(s) Summary
Dedicated mouse interaction module
src/mouse.js
Adds coordinate conversion and handlers for mouse clicks, dragging, double-clicks, zooming, panning, note editing, lane interactions, and selection behavior.
Main integration and host callbacks
src/main.js, src/host.js
Imports the extracted handlers, removes their previous implementations, and exposes the new host callbacks.
Double-click regression coverage
tests/keyboard_gutter_dblclick.test.mjs
Updates callback extraction and dependency wiring to test onDblClick from src/mouse.js.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Canvas
  participant MouseHandlers
  participant EditorState
  participant Commands
  Canvas->>MouseHandlers: Send mouse, double-click, or wheel event
  MouseHandlers->>EditorState: Update drag, selection, zoom, or note state
  MouseHandlers->>Commands: Commit note or sustain changes on mouse up
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: moving canvas pointer handlers into src/mouse.js.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/r2-step34-mouse

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mouse.js`:
- Line 434: Remove the unused x destructuring in onMouseUp, retaining only the y
value returned by getMousePos(e); verify both select and move branches continue
using their existing coordinates correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 045074af-0482-433d-87ab-d0837077680c

📥 Commits

Reviewing files that changed from the base of the PR and between 7a0f8a7 and e480d6e.

📒 Files selected for processing (4)
  • src/host.js
  • src/main.js
  • src/mouse.js
  • tests/keyboard_gutter_dblclick.test.mjs

Comment thread src/mouse.js Outdated
onMouseUp only reads y. Addresses CodeRabbit on #186 (a pre-existing unused local
moved verbatim; now removed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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