Lines
100 %
Functions
50 %
Branches
//! Focus-target resolver.
//!
//! A single canonical precedence order governs both key translation and event
//! dispatch: **Overlay > CmdLine > ConsoleInput > ViewPane**. Both
//! [`crate::keymap::translate`] and [`crate::event::apply`] call
//! [`current_focus`] so neither can drift from the other.
use crate::app::App;
#[cfg(test)]
mod tests;
/// Which layer currently owns keyboard input.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FocusTarget {
/// An overlay (modal/form) is open and intercepts all input.
Overlay,
/// The command-line palette is active.
CmdLine,
/// The console input prompt has focus.
ConsoleInput,
/// The active view pane owns input (default).
ViewPane,
}
/// Canonical focus resolver — both translate and apply must call this.
///
/// Precedence: Overlay > CmdLine > ConsoleInput > ViewPane.
/// States are structurally mutually exclusive for the higher layers:
/// opening the cmdline or an overlay is the only way to gain that focus,
/// and closing it restores the layer below.
#[must_use]
pub fn current_focus(app: &App) -> FocusTarget {
if !app.overlays.is_empty() {
FocusTarget::Overlay
} else if app.cmdline.active {
FocusTarget::CmdLine
} else if app.console_focused {
FocusTarget::ConsoleInput
} else {
FocusTarget::ViewPane