Skip to main content

Keymap

Struct Keymap 

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

Default shortcuts plus user overrides, indexed for lookup by chord.

Implementations§

Source§

impl Keymap

Source

pub fn new<'a>( platform: Platform, defaults: impl IntoIterator<Item = (&'a str, Option<&'a str>)>, ) -> Self

A keymap from (command id, default shortcut text) pairs. Commands without a default key (None) are known, so the user can bind them. Unparseable defaults are skipped and listed in Keymap::invalid_defaults.

Source

pub fn from_registry<S: Host>( registry: &Registry<S>, platform: Platform, ) -> Self

The default keymap of a command table.

Source

pub fn platform(&self) -> Platform

Source

pub fn invalid_defaults(&self) -> &[(String, String)]

Default shortcuts that did not parse: (command id, text).

Source

pub fn lookup(&self, chord: &Chord) -> Option<&str>

The command a chord runs (user bindings first, then declaration order).

Source

pub fn commands_for(&self, chord: &Chord) -> Vec<&str>

Every command bound to a chord, in lookup order.

Source

pub fn keys_for(&self, id: &str) -> &[Chord]

The keys that run a command now (its overrides, else its defaults).

Source

pub fn default_keys(&self, id: &str) -> &[Chord]

The default keys of a command.

Source

pub fn knows(&self, id: &str) -> bool

Whether the command is known to this keymap.

Source

pub fn bind(&mut self, id: &str, keys: Vec<Chord>) -> bool

Replace a command’s keys (an empty list unbinds it). Returns false for an unknown command.

Source

pub fn reset(&mut self, id: &str)

Back to the default keys of one command.

Source

pub fn reset_all(&mut self)

Source

pub fn would_conflict(&self, id: &str, chord: &Chord) -> Vec<&str>

Commands other than id that already use chord (to warn before binding).

Source

pub fn conflicts(&self) -> Vec<Conflict>

Every chord claimed by more than one command, sorted by chord.

Source

pub fn overrides(&self) -> Overrides

The overrides, to save in settings.

Source

pub fn apply_overrides(&mut self, overrides: &Overrides) -> usize

Apply saved overrides. Never fails: unknown commands and keys that don’t parse are skipped (their count is returned), and the input is capped.

Source

pub fn apply_overrides_json(&mut self, value: &Value) -> usize

Read overrides from a settings value ({"bindings": {...}}); anything malformed is ignored.

Trait Implementations§

Source§

impl Clone for Keymap

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Keymap

Source§

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

Formats the value using the given formatter. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.