LavaUI docs GitHub

enum FocusManager

Swift

enum FocusManager

Which node currently receives keyboard input.

Focus is keyed by NodeID rather than by a view value, because the view struct is rebuilt every frame while the node persists — the same reason @State storage lives on the node side.

Per window (state lives on WindowScope), which is both what the OS does and what users expect: clicking into another window and back leaves the field you were editing still focused. A single process-wide focus would also mean a key event delivered to one window reaching a field in another.

Sources/LavaUI/Focus.swift:13

Properties

static var focusedID: NodeID? { get }

The node holding keyboard focus in the current window, or nil.

Sources/LavaUI/Focus.swift:15

static var isEditingText: Bool { get }

Whether what holds focus is something typed into — a field or an editor — rather than a .focusable container such as a list. What a caret blinks for, and what an app's shortcuts should step aside for: a focused list wants Backspace to mean "up a folder", a focused field wants it to delete a character.

Sources/LavaUI/Focus.swift:61

Methods

static func clear()

Clears focus in the current window, so keys go to the default handler, if any.

Sources/LavaUI/Focus.swift:46

static func focus(_ id: NodeID, onKey: @escaping (KeyEvent) -> Bool, onChar: @escaping (Character) -> Bool)

Gives id keyboard focus in the current window, routing key events to onKey and typed characters to onChar. Each handler returns whether it consumed the input.

Sources/LavaUI/Focus.swift:25

@discardableResult static func handle(_ event: KeyEvent) -> Bool

Routes a key to the focused node. Returns true if it was consumed, so the app can fall through to global shortcuts otherwise.

Sources/LavaUI/Focus.swift:113

@discardableResult static func handle(character: Character) -> Bool

Routes a typed character to the focused node, or to the default handler when nothing is focused. Returns true if it was consumed.

Sources/LavaUI/Focus.swift:122

static func isActive(_ id: NodeID) -> Bool

Whether id receives keys right now, either by holding focus or by being the default while nothing does. What a caret should be drawn on.

Sources/LavaUI/Focus.swift:105

static func isFocused(_ id: NodeID) -> Bool

Whether id holds keyboard focus in the current window.

Sources/LavaUI/Focus.swift:18

static func resignFocus(_ id: NodeID)

Clears focus if id holds it; does nothing otherwise.

Sources/LavaUI/Focus.swift:40

static func setDefault(_ id: NodeID, onKey: @escaping (KeyEvent) -> Bool, onChar: @escaping (Character) -> Bool)

Declares where keys go when nothing is focused.

For a window whose whole purpose is one keyboard target — a terminal, a game, a full-window editor. Focus is a click-driven idea, and it is the right one where a window holds several things worth typing into; applied to a window holding exactly one, it produces an application that ignores the keyboard until you have told it which of its one thing you meant.

A fallback rather than a permanent claim, so anything that genuinely wants focus — a find bar, a rename prompt — still takes it and gives it back on its own terms. Nothing here overrides focus.

Sources/LavaUI/Focus.swift:92