Trait keybindings::Step
source · pub trait Step<Key>: Clone {
type A: Clone + Default;
type State: InputKeyState<Key, Self::Class>;
type Class: InputKeyClass<Key>;
type M: ModeKeys<Key, Self::A, Self::State> + ModeSequence<Self::Sequence, Self::A, Self::State>;
type Sequence: Eq + Hash;
// Required methods
fn is_unmapped(&self) -> bool;
fn step(&self, ctx: &mut Self::State) -> (Vec<Self::A>, Option<Self::M>);
// Provided method
fn fallthrough(&self) -> Option<Self::M> { ... }
}
Expand description
Trait for controlling the behaviour of ModalMachine during a sequence of input keys.
Required Associated Types§
sourcetype State: InputKeyState<Key, Self::Class>
type State: InputKeyState<Key, Self::Class>
A context object for managing state that accompanies actions.
sourcetype Class: InputKeyClass<Key>
type Class: InputKeyClass<Key>
Classes of input keys.
Required Methods§
sourcefn is_unmapped(&self) -> bool
fn is_unmapped(&self) -> bool
Indicates whether this step should be treated as if it’s an unmapped key, and reset to the root of the current mode.
sourcefn step(&self, ctx: &mut Self::State) -> (Vec<Self::A>, Option<Self::M>)
fn step(&self, ctx: &mut Self::State) -> (Vec<Self::A>, Option<Self::M>)
Called once the bindings that lead to this Step have been pressed.
If this returns zero actions and no mode to go to, then ModalMachine will wait for further keypresses. This allows creating intermediate Steps that only change the context, or steps that are triggered conditionally (e.g., “q” in Vim stops a recording macro if it’s already doing so, otherwise it waits for the next key to indicate the register for starting macro recording).
Provided Methods§
sourcefn fallthrough(&self) -> Option<Self::M>
fn fallthrough(&self) -> Option<Self::M>
Indicate a mode to fall through to when there is no other valid edge.
This is useful for setting up keybindings that allow executing another mode’s keys without permanently changing modes (e.g., ^O in Insert mode in Vim), or for creating a mode that represents common suffixes (e.g., Operation Pending mode in Vim).