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§

source

type A: Clone + Default

The type of output action produced after input.

source

type State: InputKeyState<Key, Self::Class>

A context object for managing state that accompanies actions.

source

type Class: InputKeyClass<Key>

Classes of input keys.

source

type M: ModeKeys<Key, Self::A, Self::State> + ModeSequence<Self::Sequence, Self::A, Self::State>

The possible modes for mapping keys.

source

type Sequence: Eq + Hash

A key type for identifying tracked action sequences which can be later repeated.

Required Methods§

source

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.

source

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§

source

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).

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<Key, A, M> Step<Key> for (Option<A>, Option<M>)
where Key: InputKey, A: Clone + Default, M: ModeKeys<Key, A, EmptyKeyState>,

§

type A = A

§

type State = EmptyKeyState

§

type Class = EmptyKeyClass

§

type M = M

§

type Sequence = EmptySequence

source§

fn is_unmapped(&self) -> bool

source§

fn step(&self, _: &mut EmptyKeyState) -> (Vec<A>, Option<M>)

Implementors§