Add touch controls for axis gizmos#668
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new mobile HUD module for touch-device users that enables keyboard-driven gizmo operations (position, rotation, scale) through on-screen controls. The HUD detects touch capability, displays axis-selection UI, and offers two control modes: arrow buttons with press-and-hold repeat behavior, or a delta-drag slider. The HUD is then integrated into the three existing gizmo keyboard handlers, preserving all existing math, physics updates, and Blockly integration while adding touch accessibility. ChangesMobile HUD and Gizmo Integration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ui/gizmos.js (1)
635-641: 💤 Low valuePotential race condition with stopAxisKeyboard reassignment.
If
exitGizmoState()is called immediately after line 636 but before thesetTimeoutcallback executes, the HUD is stopped andstopAxisKeyboardis set tonull. When thesetTimeoutfires, it creates a keyboard handler and reassignsstopAxisKeyboard, leaving an active keyboard handler after exit. While the window is very small (a single event loop tick), consider guarding with a cancellation flag:🔧 Suggested fix using a cancellation flag
+ let cancelled = false; const stopHud = createGizmoMobileHud({ onMove, stepNormal: DEFAULT_CURSOR, stepFast: FAST_CURSOR, mode: "arrows" }); - stopAxisKeyboard = () => stopHud?.(); + stopAxisKeyboard = () => { cancelled = true; stopHud?.(); }; setTimeout(() => { + if (cancelled) return; const stopKeyboard = createAxisKeyboardHandler({ onMove, onConfirm, onCancel, stepNormal: DEFAULT_CURSOR, stepFast: FAST_CURSOR }); stopAxisKeyboard = () => { stopKeyboard(); stopHud?.(); }; }, 0);🤖 Prompt for 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. In `@ui/gizmos.js` around lines 635 - 641, The reassignment of stopAxisKeyboard inside the setTimeout can resurrect a keyboard handler after exitGizmoState; fix by introducing a local cancellation flag (e.g., let cancelled = false) captured by the setTimeout closure, set cancelled = true when exit/cleanup runs (where stopHud and stopAxisKeyboard are cleared), and inside the setTimeout: after creating stopKeyboard check the flag—if cancelled, immediately call stopKeyboard() and do not reassign stopAxisKeyboard; otherwise assign stopAxisKeyboard = () => { stopKeyboard(); stopHud?.(); } to ensure no handler remains active after exitGizmoState.
🤖 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.
Nitpick comments:
In `@ui/gizmos.js`:
- Around line 635-641: The reassignment of stopAxisKeyboard inside the
setTimeout can resurrect a keyboard handler after exitGizmoState; fix by
introducing a local cancellation flag (e.g., let cancelled = false) captured by
the setTimeout closure, set cancelled = true when exit/cleanup runs (where
stopHud and stopAxisKeyboard are cleared), and inside the setTimeout: after
creating stopKeyboard check the flag—if cancelled, immediately call
stopKeyboard() and do not reassign stopAxisKeyboard; otherwise assign
stopAxisKeyboard = () => { stopKeyboard(); stopHud?.(); } to ensure no handler
remains active after exitGizmoState.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 424ae1bd-140d-41b7-a5d1-5b55bebfb629
📒 Files selected for processing (2)
ui/gizmo-mobile-hud.jsui/gizmos.js
Summary
Adds touch controls for axis-based gizmos (move, resize, rotate)
AI usage
Claude Sonnet 4.6 wrote all of the code in this PR. The plan was designed and refined by me in steps.
Summary by CodeRabbit
New Features
Improvements