pub enum ModalState {
Normal {
pending: PendingOp,
},
Insert,
Visual,
VisualLine,
Command {
minibuffer: String,
},
}Expand description
The modal state machine — a SUM over the five editor modes, each carrying ONLY the data valid in that mode.
#[serde(tag = "mode")] keeps the wire shape readable ({"mode": "Normal", "pending": {…}}) and is the parse boundary: a deserialized
value can only be one of the legal shapes.
Variants§
Implementations§
Source§impl ModalState
impl ModalState
pub fn new() -> Self
Sourcepub const fn mode(&self) -> Mode
pub const fn mode(&self) -> Mode
The Mode discriminant of the current state — the projection the
renderers + keymap dispatch read.
Sourcepub fn enter_normal(&mut self)
pub fn enter_normal(&mut self)
Enter Mode::Normal with no pending count/operator.
Sourcepub fn enter_insert(&mut self)
pub fn enter_insert(&mut self)
Enter Mode::Insert. Any pending count/operator/minibuffer is
dropped by construction.
Sourcepub fn enter_visual(&mut self)
pub fn enter_visual(&mut self)
Enter Mode::Visual.
Sourcepub fn enter_visual_line(&mut self)
pub fn enter_visual_line(&mut self)
Enter Mode::VisualLine.
Sourcepub fn enter_command(&mut self)
pub fn enter_command(&mut self)
Enter Mode::Command with an empty minibuffer.
Sourcepub fn escape(&mut self)
pub fn escape(&mut self)
Leave any mode back to a clean Mode::Normal — the <Esc>
transition.
Sourcepub fn enter(&mut self, mode: Mode)
pub fn enter(&mut self, mode: Mode)
Dispatch to the matching typed transition for a target Mode.
Kept for callers that hold a runtime Mode value (e.g. the keymap’s
Action::ChangeMode(Mode)); it is sugar over the enter_* methods
and preserves the invariant the same way.
Sourcepub fn set_operator(&mut self, op: Operator)
pub fn set_operator(&mut self, op: Operator)
Set the pending operator. No-op unless in Mode::Normal.
Sourcepub fn append_count(&mut self, digit: u32)
pub fn append_count(&mut self, digit: u32)
Append a digit to the pending count. No-op unless in Mode::Normal.
Sourcepub const fn pending_count(&self) -> Option<u32>
pub const fn pending_count(&self) -> Option<u32>
The current pending count (None ⇒ none accumulated). Always None
outside Mode::Normal.
Sourcepub const fn pending_operator(&self) -> Option<Operator>
pub const fn pending_operator(&self) -> Option<Operator>
The current pending operator. Always None outside Mode::Normal.
Sourcepub fn consume_count(&mut self) -> u32
pub fn consume_count(&mut self) -> u32
Take the pending count, leaving it cleared; defaults to 1 (and at
least 1). No-op-returning-1 outside Mode::Normal.
Sourcepub fn clear_count(&mut self)
pub fn clear_count(&mut self)
Clear any pending count without consuming its value.
Sourcepub fn consume_operator(&mut self) -> Option<Operator>
pub fn consume_operator(&mut self) -> Option<Operator>
Take the pending operator, leaving it cleared.
Sourcepub fn minibuffer(&self) -> &str
pub fn minibuffer(&self) -> &str
Read the command-mode minibuffer (empty string outside
Mode::Command).
Sourcepub fn push_minibuffer(&mut self, ch: char)
pub fn push_minibuffer(&mut self, ch: char)
Push a char onto the minibuffer. No-op unless in Mode::Command.
Sourcepub fn pop_minibuffer(&mut self) -> Option<char>
pub fn pop_minibuffer(&mut self) -> Option<char>
Pop a char off the minibuffer. None unless in Mode::Command.
Sourcepub fn push_minibuffer_str(&mut self, s: &str)
pub fn push_minibuffer_str(&mut self, s: &str)
Append a raw fragment to the minibuffer (used by the command
registry’s __quit__ sentinel handshake). No-op outside
Mode::Command.
Sourcepub fn clear_minibuffer(&mut self)
pub fn clear_minibuffer(&mut self)
Clear the minibuffer in place. No-op outside Mode::Command.
Trait Implementations§
Source§impl Clone for ModalState
impl Clone for ModalState
Source§fn clone(&self) -> ModalState
fn clone(&self) -> ModalState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModalState
impl Debug for ModalState
Source§impl Default for ModalState
impl Default for ModalState
Source§impl<'de> Deserialize<'de> for ModalState
impl<'de> Deserialize<'de> for ModalState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ModalState
Source§impl JsonSchema for ModalState
impl JsonSchema for ModalState
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read more