refactor(editor): move canvas pointer handlers to src/mouse.js (R2, step 34) - #186
Merged
Conversation
…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>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR extracts editor mouse interactions from ChangesMouse interaction refactor
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
src/host.jssrc/main.jssrc/mouse.jstests/keyboard_gutter_dblclick.test.mjs
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>
This was referenced Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Step 34 of the R2 module-extraction refactor: move the canvas pointer event handlers out of
src/main.jsinto a new native ES modulesrc/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'sinit()attaches them to the canvas;getMousePosremains a host hook, now sourced here.showAddNote,updateZoomDisplay,partsViewOnMouseDown,partsViewOnDblClick.no-undefgate confirmed no over-removal.tests/keyboard_gutter_dblclick.test.mjsretargeted to sliceonDblClickfrommouse.jsand inject ahoststub (onDblClicknow reachesshowAddNote/partsViewOnDblClickthrough host).main.js drops ~595 lines. 35 modules.
Verification
no-undefclean onmouse.js.verify_mouse.py) drives real pointer events: ctrl+wheel zooms the readout (100→138%, provinghost.updateZoomDisplay), clicking a note selects it and reveals the inspector, double-clicking empty grid opens the add-note dialog (provinghost.showAddNote), and dragging a note moves it (provinghost.draw) — zero page errors. Both new hooks negative-checked.🤖 Generated with Claude Code
Summary by CodeRabbit