KeyBinding class
A single key binding that maps key events to actions.
Bindings are designed to stay pure/side-effect free except for the action you provide. This keeps them trivial to test and reason about when multiple sets are composed together.
This is the core building block of the KeyBindings system. Each binding can:
- Match one or more key types
- Execute an action when matched
- Provide a hint label and description for hint display in views/prompts
Constructors
-
KeyBinding({required Set<
KeyEventType> keys, required KeyActionResult action(KeyEvent event), bool charMatcher(String char)?, String? hintLabel, String? hintDescription}) -
Creates a binding that matches the provided
keys. For convenience, prefer thesingle,multi, orcharfactories when possible.const - KeyBinding.char(bool matcher(String char), KeyActionResult action(KeyEvent event), {String? hintLabel, String? hintDescription})
-
Creates a binding for character input matching a predicate.
factory
-
KeyBinding.multi(Set<
KeyEventType> keys, KeyActionResult action(KeyEvent event), {String? hintLabel, String? hintDescription}) -
Creates a binding for multiple key types.
factory
- KeyBinding.single(KeyEventType key, KeyActionResult action(KeyEvent event), {String? hintLabel, String? hintDescription})
-
Creates a binding for a single key type.
factory
Properties
- action → KeyActionResult Function(KeyEvent event)
-
The action to execute when this binding matches.
final
- charMatcher → bool Function(String char)?
-
Optional character matcher (for
KeyEventType.charevents).final - hashCode → int
-
The hash code for this object.
no setterinherited
- hintDescription → String?
-
Description for hints (e.g., "navigate", "confirm", "cancel")
final
- hintLabel → String?
-
Short label for hints (e.g., "←/→", "Enter", "Esc")
final
-
keys
→ Set<
KeyEventType> -
Key types that trigger this binding.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
matches(
KeyEvent event) → bool - Checks if this binding matches the given event.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
tryHandle(
KeyEvent event) → KeyActionResult? - Attempts to handle the event. Returns the result if matched, null otherwise.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited