refactor: extract file-tree key handling into key_actions module#2042
refactor: extract file-tree key handling into key_actions module#2042sximelon wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the file-tree keyboard event handling logic into a dedicated key_actions module to improve the maintainability of the main event loop. The review highlights a regression where the omission of the file_tree_visible check causes keyboard events to be intercepted even when the file tree is hidden. Further feedback points out stale documentation referencing an undefined KeyActionResult type and suggests consistent use of inlined variables in format strings.
| //! control-flow change (shutdown, return to caller) communicate via | ||
| //! [`KeyActionResult`]. |
| if let Some(rel_path) = file_tree.activate() { | ||
| let path_str = rel_path.to_string_lossy().to_string(); | ||
| app.status_message = Some(format!("Attached @{path_str}")); | ||
| app.insert_str(&format!("@{} ", path_str)); |
There was a problem hiding this comment.
Inconsistent format string style. Line 44 uses inlined variables (@{path_str}), while line 45 uses positional placeholders (@{} ). It is better to use the inlined style for consistency and to match the original code.
| app.insert_str(&format!("@{} ", path_str)); | |
| app.insert_str(&format!("@{path_str} ")); |
Restore file_tree_visible guard, remove stale KeyActionResult docs, unify format string style.
Summary
Move the file-tree keyboard event handler (Up/Down/Enter/Esc) out of ui::run_event_loop into a dedicated key_actions module.
The new handle_file_tree_key function returns bool to signal whether the key was consumed, keeping the call site a single-line delegation.
Testing
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-featurescargo test --workspace --all-featuresChecklist