Skip to content

Conversation

@daisuke8000
Copy link
Owner

Summary

  • Refactor monolithic handle_key() method (254 lines) into focused helper methods
  • Improve code organization, testability, and maintainability

Changes

Before: Single monolithic method

fn handle_key(&mut self, code: KeyCode, modifiers: KeyModifiers) {
    // 254 lines of nested conditionals and match statements
}

After: Orchestrator with specialized handlers

fn handle_key(&mut self, code: KeyCode, modifiers: KeyModifiers) {
    if self.handle_overlay_keys(code) { return; }
    if self.handle_search_mode_keys(code, modifiers) { return; }
    if self.handle_global_keys(code, modifiers) { return; }
    if code == KeyCode::Enter && self.handle_enter_key() { return; }
    self.content.handle_key(...);
}

New helper methods

Method Lines Responsibility
handle_overlay_keys() ~35 RecordDetail, Help overlay handling
handle_search_mode_keys() ~30 Search input mode processing
handle_global_keys() ~50 Quit, help, tab switching, refresh
handle_escape_key() ~30 Navigation back logic
handle_refresh() ~15 Data reload for current view
handle_enter_key() ~65 Content-specific Enter actions
handle_key() ~25 Simple orchestrator

Benefits

  • Testability: Each handler can be tested independently
  • Debugging: Easier to locate issues in specific handlers
  • Maintenance: Changes are isolated to relevant handlers
  • Readability: Clear separation of concerns

Test plan

  • cargo test --package mbr-tui - All 32 tests pass
  • cargo clippy --package mbr-tui - No warnings
  • cargo fmt - Applied

Refactor the monolithic handle_key() method (254 lines) into focused
helper methods for better readability and maintainability:

- handle_overlay_keys(): RecordDetail and Help overlay handling
- handle_search_mode_keys(): Search input mode processing
- handle_global_keys(): Quit, help, tab switching, refresh
- handle_escape_key(): Navigation back logic
- handle_refresh(): Data reload for current view
- handle_enter_key(): Content-specific Enter actions

The new handle_key() is now a simple 25-line orchestrator that delegates
to specialized handlers in priority order:
1. Overlay keys (highest priority)
2. Search mode keys
3. Global keybindings
4. Enter key for content actions
5. Remaining keys to ContentPanel

This separation improves:
- Testability: Each handler can be tested independently
- Debugging: Easier to locate issues in specific handlers
- Maintenance: Changes are isolated to relevant handlers
@daisuke8000 daisuke8000 merged commit af19922 into main Dec 20, 2025
1 check passed
@daisuke8000 daisuke8000 deleted the refactor/pr7-app-responsibility-separation branch December 20, 2025 13:52
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