Skip to main content

Module modal

Module modal 

Source
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:

FromKeyTo
Normali a o …ModalState::Insert
Normalv / V / <C-v>ModalState::Visual (charwise / linewise / blockwise)
Normalgh / gH / g<C-h>ModalState::Select
Normalan operator (d, c, y …)ModalState::OperatorPending
Normal:ModalState::Command
Normal/ / ?ModalState::Search
NormalRModalState::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§

ModalState
The vim modal state of a buffer — which grammar a keystroke is read in.
SearchDirection
Which way a search runs: / searches forward, ? backward. n repeats in the same direction, N in the opposite one.
VisualKind
The shape of a Visual / Select selection.