Skip to main content

ModeChanged

Struct ModeChanged 

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

Previous mode description (for display/logging).

§to: String

New mode description (for display/logging).

Implementations§

Source§

impl ModeChanged

Source

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

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ModeChanged

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModeChanged

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Event for ModeChanged

Source§

fn priority(&self) -> u32

Priority for handler dispatch ordering. Read more
Source§

fn batchable(&self) -> bool

Whether this event can be batched with similar events. Read more
Source§

impl PartialEq for ModeChanged

Source§

fn eq(&self, other: &ModeChanged) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ModeChanged

Source§

impl StructuralPartialEq for ModeChanged

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.