Repository navigation
refactor(runtime): type menu navigation directions - #500
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (4)
✨ Finishing Touches📝 Generate docstrings
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.
🟢 Approval recommended
It is a small, mechanical, behavior-preserving type-safety refactor fully contained in the menu module, with all callers updated, visibility correctly narrowed, and existing test coverage retained.
0 open findings
What changed in this PR
This PR replaces the untyped i32 argument of the menu move_hover navigation method with a dedicated MenuDirection::{Next, Previous} enum, making invalid steps (0, 2, etc.) unrepresentable. It is a type-safety refactor internal to the neomacs-display-runtime menu module, preserving all existing traversal, wrapping, separator/disabled-item skipping, and submenu behavior.
Changes:
- Introduce
pub(super) enum MenuDirection(Next = 1,Previous = -1) derivingnum_enum::IntoPrimitivewith#[repr(i32)], and retypemove_hoverto accept it (nowpub(super)), converting to the internalstepviadirection.into(). - Update keyboard handlers and all tests (session + opt-in native) to pass named variants.
- Add the existing workspace
num_enumdependency to the crate (reflected inCargo.lock).
| File | Description |
|---|---|
crates/neomacs-display-runtime/src/menus/session.rs |
Adds MenuDirection enum; retypes/narrows move_hover and converts the enum to the internal step. |
crates/neomacs-display-runtime/src/menus/interaction.rs |
Updates arrow/Home/End key handlers to pass MenuDirection variants. |
crates/neomacs-display-runtime/src/menus/session/tests/session_test.rs |
Migrates hover tests to named variants; refreshes two now-stale comments. |
crates/neomacs-display-runtime/src/menus/tests/native_test.rs |
Imports and uses MenuDirection::Next in the opt-in native menu test. |
crates/neomacs-display-runtime/Cargo.toml |
Adds num_enum.workspace = true. |
Cargo.lock |
Records the new num_enum dependency edge for the runtime crate. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Menu hover navigation accepted any
i32, although every caller intended a single forward or backward step. Replace the argument withMenuDirection::{Next, Previous}so unsupported steps such as zero or two cannot be passed.Update keyboard handlers, session tests, and the opt-in native menu test to use named variants. Keep the internal traversal, wrapping, disabled-item skipping, and submenu behavior unchanged. Restrict the navigation method and direction type to the menu module. Derive
num_enum::IntoPrimitivewith#[repr(i32)]and explicit1/-1discriminants, then convert usingdirection.into(). Reuse the existing workspacenum_enumdependency; the lockfile adds only the runtime crate dependency edge, with no package version changes.Validation: all 59 focused menu session tests pass. Formatting and diff checks pass. Tests retain the related
tests/location and_test.rssuffix.