pub struct ModeChanged {
pub from: String,
pub to: String,
/* private fields */
}Expand description
Editor mode changed.
Emitted after a mode transition occurs (e.g., Normal → Insert). The mode strings are intentionally generic - policy (specific modes) is defined by the runtime and modules.
§Type-Safe Mode Transitions
When target_mode is set, it provides the exact ModeId to transition to.
This enables event-driven mode transitions without hardcoding command names
in the runner layer.
§Example
// Commands emit with target_mode for type-safe transitions
ctx.event_bus.emit(ModeChanged::with_mode_id("normal", editor_visual_mode));
// Runner subscribes and updates mode_stack from the event
bus.subscribe::<ModeChanged, _>(priority::CORE, |event| {
if let Some(mode_id) = event.target_mode() {
app.mode_stack.set(mode_id.clone());
}
EventResult::Handled
});Fields§
§from: StringPrevious mode description (for display/logging).
to: StringNew mode description (for display/logging).
Implementations§
Source§impl ModeChanged
impl ModeChanged
Sourcepub fn new(from: impl Into<String>, to: impl Into<String>) -> Self
pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self
Create a new mode change event with string descriptions only.
Use this for backward compatibility or when the target mode is implicit (e.g., commands that emit events for logging only).
Sourcepub fn with_mode_id(from: impl Into<String>, target: ModeId) -> Self
pub fn with_mode_id(from: impl Into<String>, target: ModeId) -> Self
Create a mode change event with a specific target mode ID.
The runner subscribes to these events and updates the mode stack
using the provided ModeId, eliminating the need for hardcoded
command name mappings.
Sourcepub const fn target_mode(&self) -> Option<&ModeId>
pub const fn target_mode(&self) -> Option<&ModeId>
Get the target mode ID, if set.
Returns Some(&ModeId) when the event was created with with_mode_id(),
None for legacy events created with just string descriptions.
Sourcepub const fn has_target_mode(&self) -> bool
pub const fn has_target_mode(&self) -> bool
Check if this event has a type-safe target mode.
Trait Implementations§
Source§impl Clone for ModeChanged
impl Clone for ModeChanged
Source§fn clone(&self) -> ModeChanged
fn clone(&self) -> ModeChanged
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more