refactor(editor): move the input layer to src/input.js (R2, step 36) - #188
Conversation
Extract the entire remaining "Mouse interactions" banner — the keyboard shortcut dispatch (onKeyDown), all the _editorX command implementations, the bookmarks/duplicate/section-cmds command clusters, the shortcut panel, and the canvas context menu (onContextMenu/showSectionMenu) — out of the src/main.js monolith into a new native ES module. The banner is now empty and gone. Enabled by landing tab-preview first (#187): the two tab-preview couplings (_editorShowTabPreview, _tabPreviewKeyPolicyPure) are now plain module imports. - src/input.js (~1240 lines): imports across ~20 modules; 7 symbols exported back (onKeyDown + onContextMenu, wired onto the canvas by main.js init(); _editorCurrentNoteIndices/_editorSeekToTime/_editorSnapStepSeconds host hooks; _bookmarks + the editorWaveformVisible live binding, read by the draw path). - 5 new host hooks for the composition-root symbols the commands call: editorCycleViewMode, editorMovePart, editorToggleKeyHighlight, editorTogglePartsView, tempoResolvedMeasureIdx. - The 4 @pure blocks (shortcut-panel-hint, bookmarks, duplicate, section-cmds) and the command classes inside them stay export-free (internal), so the JS suite's new-Function slices stay valid. - Removed 72 now-dead main.js imports (used only by the moved layer) — strict no-undef confirmed no over-removal. - 4 tests retargeted to slice from input.js (bookmarks, duplicate_selection, section_undo, roll_position_cycle). main.js drops ~1243 lines. 37 modules. Verified: 90/90 JS suites pass, ESLint gate clean (0 errors), strict no-undef clean on input.js, Codex preflight 0 regressions (init() attachment + editorWaveformVisible live binding confirmed). New headless harness drives REAL input: right-click opens the context menu (onContextMenu), the shortcut panel toggles, editorRunShortcutCommand routes 'toggleKeyHighlight'/'togglePartsView' into their new host hooks (distinct status each), and a real Shift+A keypress routes through onKeyDown to the parts-view command — zero page errors. The two new hooks + onKeyDown negative-checked. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe editor input layer is moved into ChangesEditor input and integration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant onKeyDown
participant editorRunEofCommand
participant EditorCommand
participant host
User->>onKeyDown: keyboard shortcut or edit event
onKeyDown->>editorRunEofCommand: dispatch command id
editorRunEofCommand->>EditorCommand: execute editor operation
EditorCommand->>host: update editor state or tempo hooks
host->>User: refresh editor state
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: 3
🤖 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/host.js`:
- Line 78: The default tempoResolvedMeasureIdx resolver should be inert rather
than selecting measure zero. Update the resolver in the host configuration to
return a negative value (such as -1), so input.js will not apply the
time-signature edit when no measure has been resolved.
In `@src/input.js`:
- Around line 934-940: Replace the HTML-string construction in the section-menu
builder with DOM button creation and textContent assignments, especially in the
nearSection rename and delete actions. Preserve the existing classes and
data-action attributes, append the buttons to menu, and ensure nearSection.name
is only inserted as text rather than interpolated into innerHTML.
- Around line 1147-1153: Update the guitar/keys delete guard in the keyboard
handler to also require Tempo Map mode to be inactive, using the same tempo-mode
predicate as the duplicate, copy, and paste handlers; ensure stale S.sel notes
are not passed to DeleteNotesCmd when no sync point is selected during Tempo Map
mode.
🪄 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: f82ad9c8-c11f-4b7c-a93b-b437d04d0efe
📒 Files selected for processing (7)
src/host.jssrc/input.jssrc/main.jstests/bookmarks.test.mjstests/duplicate_selection.test.mjstests/roll_position_cycle.test.mjstests/section_undo.test.mjs
…n-menu XSS, tempo-mode delete guard - host.js: tempoResolvedMeasureIdx default 0 -> -1 so an unwired hook is inert (callers apply the time-signature edit only on >= 0). This one is a regression from this PR's new hook. - input.js showSectionMenu: build the buttons as DOM nodes with textContent instead of interpolating the user-authored section name into innerHTML — removes a stored-XSS sink. (Pre-existing, moved verbatim; hardened here.) - input.js Delete key: add the !S.tempoMapMode guard (matching duplicate/copy/ paste) so a stale selection can't delete hidden notes while Tempo Map mode is active. (Pre-existing, moved verbatim.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Step 36 of the R2 module-extraction refactor: move the entire remaining input layer out of
src/main.jsinto a new native ES modulesrc/input.js. The "Mouse interactions" banner is now empty and gone.Covers: the keyboard shortcut dispatch (
onKeyDown), all the_editorXcommand implementations, the bookmarks / duplicate / section-cmds command clusters, the shortcut panel, and the canvas context menu (onContextMenu/showSectionMenu).Enabled by tab-preview (#187)
Landing tab-preview first turned its two couplings (
_editorShowTabPreview,_tabPreviewKeyPolicyPure) into plain module imports instead of awkward host hooks — that's why this cut is clean.How the seam is drawn
src/input.js(~1,240 lines): imports across ~20 modules; 7 symbols exported back —onKeyDown+onContextMenu(wired onto the canvas by main.jsinit());_editorCurrentNoteIndices/_editorSeekToTime/_editorSnapStepSeconds(host hooks);_bookmarks+ theeditorWaveformVisiblelive binding (both read by the draw path).editorCycleViewMode,editorMovePart,editorToggleKeyHighlight,editorTogglePartsView,tempoResolvedMeasureIdx.@pureblocks (shortcut-panel-hint, bookmarks, duplicate, section-cmds) and the command classes inside them stay export-free (internal), so the JS suite'snew Functionslices stay valid.no-undefconfirmed no over-removal.input.js(bookmarks, duplicate_selection, section_undo, roll_position_cycle).main.js drops ~1,243 lines. 37 modules.
Verification
no-undefclean oninput.js.editorWaveformVisiblelive binding confirmed).verify_input.py) drives real input: right-click opens the context menu (onContextMenu), the shortcut panel toggles,editorRunShortcutCommandroutes'toggleKeyHighlight'/'togglePartsView'into their new host hooks (distinct status each), and a real Shift+A keypress routes throughonKeyDownto the parts-view command — zero page errors. The two new hooks +onKeyDownnegative-checked.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests