Skip to content

Move gizmo: keyboard controls#556

Merged
tracygardner merged 5 commits intoflipcomputing:mainfrom
lawsie:axis-tools-kb-control
Apr 20, 2026
Merged

Move gizmo: keyboard controls#556
tracygardner merged 5 commits intoflipcomputing:mainfrom
lawsie:axis-tools-kb-control

Conversation

@lawsie
Copy link
Copy Markdown
Contributor

@lawsie lawsie commented Apr 20, 2026

Summary

Add keyboard controls for move gizmo

When the move gizmo is selected:

  • If there is no current selection, allow mouse/keyboard cursor selection, otherwise use current selection
  • Move the object using axis controls
    Arrow keys plus page up/page down
    X, Y or Z to fix on an axis, then use arrow keys to move only on that axis
  • Press Enter to confirm the move - keeps current selection
  • Press Esc to escape move mode - removes current selection
  • Blockly block properly updates values on move

Known issues

  • If you select a mesh, move it, then click on another mesh, move handles still display on that mesh. Moving the mesh using the cursor works fine but using the arrow keys to move the mesh also moves the camera. You can't get into this situation using keyboard controls only.

Summary by CodeRabbit

  • Bug Fixes & Refactor
    • Improved gizmo interaction workflow with more reliable state management
    • Enhanced keyboard and mouse control integration for position and selection gizmos
    • Fixed inconsistent behavior when toggling between different gizmos
    • Better cleanup and cursor handling during gizmo interactions

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

This PR centralizes gizmo interaction logic in ui/gizmos.js by introducing three shared helper functions—exitGizmoState() for cleanup, startMoveKeyboardHandler() for keyboard-based mesh movement, and pickMeshFromScene() for unified picking—then refactors existing gizmo handlers to use these abstractions.

Changes

Cohort / File(s) Summary
Gizmo Helper Functions
ui/gizmos.js
Added exitGizmoState() to centralize cleanup (axes, observers, active classes, cursor), startMoveKeyboardHandler(mesh) to enable keyboard movement with configurable step sizes, and pickMeshFromScene(onPicked) to unify click/keyboard picking with cursor management.
Gizmo Toggle & Position Handler
ui/gizmos.js
Updated toggleGizmo() to call exitGizmoState() when deactivating; refactored handlePositionGizmo() to manage a dedicated observer, handle mesh reattachment, and implement confirm/cancel with proper state exit and focus return.
Select Handler Refactoring
ui/gizmos.js
Simplified handleSelectGizmo() by replacing inline keyboard/pointer logic with a call to pickMeshFromScene() for cleaner mesh selection flow.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through tangled gizmo threads,
Weaving helpers where chaos once spread,
exitGizmoState cleans with grace,
Pick and move now share one place,
Chaos tamed in organized line! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Move gizmo: keyboard controls' directly and clearly summarizes the main change: adding keyboard controls for the move gizmo, which is the primary objective.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ui/gizmos.js`:
- Around line 502-518: pickMeshFromScene creates both keyboard picking and a
pointer observer but the abort/mouse/keyboard paths each clean up different
pieces, leaving the pointer observer or keyboard mode active; centralize cleanup
into a single function (either extend exitGizmoState or add cleanupScenePick)
that: stops keyboard picking (stopAxisKeyboard/clear its variable), removes the
pointer observer (the pointer observer variable used in pickMeshFromScene),
removes positionGizmoObserver via
gizmoManager.onAttachedToMeshObservable.remove(positionGizmoObserver) and clears
positionGizmoObserver, removes active classes, disables gizmos and resets
cursor; then call this single cleanup from pickMeshFromScene’s mouse-pick
handler, keyboard-pick handler, and any abort/cancel paths so no stale observers
remain.
- Around line 593-598: The early return when the gizmo button is active skips
teardown for duplicate-mode, leaving activeDuplicatePickHandler and its window
click listener armed; before calling exitGizmoState() (in the block checking
button.classList.contains("active")), run the same duplicate-mode cleanup that's
done later (remove/clear activeDuplicatePickHandler and remove the window click
listener) or refactor so duplicate teardown is moved out of disableGizmos() into
explicit handlers (e.g., toggleGizmo() and Escape handler) and invoke that
teardown here to ensure no duplicate placement remains active.
🪄 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

Run ID: a57b34d7-fe11-4033-adde-a7d17cfaee73

📥 Commits

Reviewing files that changed from the base of the PR and between 2dad064 and fdd3626.

📒 Files selected for processing (1)
  • ui/gizmos.js

Comment thread ui/gizmos.js
Comment thread ui/gizmos.js
@lawsie lawsie marked this pull request as draft April 20, 2026 12:28
@lawsie lawsie marked this pull request as ready for review April 20, 2026 13:07
@lawsie lawsie mentioned this pull request Apr 20, 2026
11 tasks
@tracygardner tracygardner merged commit d3db3c8 into flipcomputing:main Apr 20, 2026
5 checks passed
@lawsie lawsie deleted the axis-tools-kb-control branch April 20, 2026 13:22
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