Skip to main content

Keymap

Struct Keymap 

Source
pub struct Keymap { /* private fields */ }
Expand description

A set of key→command bindings for one platform.

Implementations§

Source§

impl Keymap

Source

pub fn new(mac: bool, bindings: Vec<(&str, Command)>) -> Self

Build a keymap. mac selects whether Mod means Cmd/Meta (macOS) or Ctrl. Binding strings use --separated modifiers, e.g. "Mod-b", "Mod-Shift-z", "Enter".

Source

pub fn handle( &self, state: &EditorState, press: &KeyPress, dispatch: Option<&mut Dispatch<'_>>, ) -> bool

Handle a key press. Returns whether a binding matched (and ran, if a dispatch was given and the command applied).

Lookup is two-pass: first the exact canonical form, then — if shift was held and the key isn’t a lowercase ASCII letter — the same form with shift stripped. That mirrors the browser convention where a key like > or ? is always produced with Shift, so a binding like "Mod->" shouldn’t have to spell out Shift.

Source

pub fn add(&mut self, spec: &str, command: Command)

Add or replace a binding by its Mod--using key spec (e.g. "Mod-b"). Extensions use this to inject bindings on top of base_keymap.

Source

pub fn add_chained(&mut self, spec: &str, command: Command)

Add a binding, chaining it in front of any existing binding for the same key rather than replacing it: the new command is tried first and the previous one becomes its fallback. Because well-behaved commands report false (and do nothing) when they don’t apply, this lets independent extensions cooperate on a shared key — e.g. Tab running cell-navigation inside a table and list-indent inside a list, each a no-op in the other’s context.

Source

pub fn len(&self) -> usize

Number of bindings.

Source

pub fn is_empty(&self) -> bool

Whether the keymap has no bindings.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Keymap

§

impl !Send for Keymap

§

impl !Sync for Keymap

§

impl !UnwindSafe for Keymap

§

impl Freeze for Keymap

§

impl Unpin for Keymap

§

impl UnsafeUnpin for Keymap

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