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:
-
Leaf-first, bubble up: Input is dispatched to the deepest focused element first. If not consumed, it bubbles up to parents.
-
Explicit consumption: Handlers return
InputResult::Consumedto stop propagation orInputResult::Ignoredto let parents try. -
Modals consume by default: Modal dialogs (Settings, Prompts) should return
Consumedfor unhandled keys to prevent input leakage. -
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§
- Input
Context - Context passed to input handlers, providing access to shared state.
Enums§
- Deferred
Action - Actions that need to be executed after input handling completes. These are operations that require mutable access to Editor.
- Input
Result - Result of handling an input event.
- Terminal
Mouse Button - Mouse buttons for terminal forwarding.
- Terminal
Mouse Event Kind - Mouse event kinds for terminal forwarding. Simplified from crossterm’s MouseEventKind to capture what we need.
Traits§
- Input
Handler - 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