Expand description
Modal state – a buffer-level state machine in front of the buffer (DESIGN.md §5.2). Orthogonal to major / minor modes.
This crate owns the state type only. Transitions are not methods here:
a command asks for one by returning Effect::EnterMode
(or AppEffect::EnterMode), and the host
applies it to the focused buffer’s modal field. That keeps the state
machine’s policy (which chord enters which state) in the keymap and the
command bodies, and its storage in the host, while every layer agrees on
one vocabulary.
The usual vim transitions, for orientation:
| From | Key | To |
|---|---|---|
| Normal | i a o … | ModalState::Insert |
| Normal | v / V / <C-v> | ModalState::Visual (charwise / linewise / blockwise) |
| Normal | gh / gH / g<C-h> | ModalState::Select |
| Normal | an operator (d, c, y …) | ModalState::OperatorPending |
| Normal | : | ModalState::Command |
| Normal | / / ? | ModalState::Search |
| Normal | R | ModalState::Replace |
| any | <Esc> | ModalState::Normal |
§Examples
use lattice_grammar::{ModalState, VisualKind};
let state = ModalState::default();
assert_eq!(state, ModalState::Normal);
// `V` in Normal: the host applies `EnterMode(Visual(Linewise))`.
let state = ModalState::Visual(VisualKind::Linewise);
assert!(state.is_visual());
assert!(!state.is_select()); // same geometry, different dispatch
assert!(!state.is_operator_pending());Enums§
- Modal
State - The vim modal state of a buffer — which grammar a keystroke is read in.
- Search
Direction - Which way a search runs:
/searches forward,?backward.nrepeats in the same direction,Nin the opposite one. - Visual
Kind - The shape of a Visual / Select selection.