Skip to main content

Module handler

Module handler 

Source
Expand description

Hierarchical Input Handling System

This module provides a tree-based input dispatch system where input events flow through a hierarchy of handlers. The design follows these principles:

  1. Leaf-first, bubble up: Input is dispatched to the deepest focused element first. If not consumed, it bubbles up to parents.

  2. Explicit consumption: Handlers return InputResult::Consumed to stop propagation or InputResult::Ignored to let parents try.

  3. Modals consume by default: Modal dialogs (Settings, Prompts) should return Consumed for unhandled keys to prevent input leakage.

  4. No capture phase: Unlike DOM events, there’s no capture phase. This keeps the model simple and predictable.

§Example

impl InputHandler for MyPanel {
    fn handle_input(&mut self, event: &KeyEvent, ctx: &mut InputContext) -> InputResult {
        // Let focused child try first
        if let Some(child) = self.focused_child_mut() {
            if child.handle_input(event, ctx) == InputResult::Consumed {
                return InputResult::Consumed;
            }
        }

        // Handle at this level
        match event.code {
            KeyCode::Up => { self.move_up(); InputResult::Consumed }
            KeyCode::Down => { self.move_down(); InputResult::Consumed }
            _ => InputResult::Ignored // Let parent handle
        }
    }
}

Structs§

InputContext
Context passed to input handlers, providing access to shared state.

Enums§

DeferredAction
Actions that need to be executed after input handling completes. These are operations that require mutable access to Editor.
InputResult
Result of handling an input event.
TerminalMouseButton
Mouse buttons for terminal forwarding.
TerminalMouseEventKind
Mouse event kinds for terminal forwarding. Simplified from crossterm’s MouseEventKind to capture what we need.

Traits§

InputHandler
Trait for elements that can handle input events.

Functions§

is_key
Helper to check for common key combinations.
is_key_with_alt
is_key_with_ctrl
is_key_with_shift