Skip to main content

Keymap

Struct Keymap 

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

Implementations§

Source§

impl Keymap

Source

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

Returns keymap conflicts, defined as multiple bindings sharing the same (platform, when, sequence) tuple (ADR 0021 section 7).

This is intended for diagnostics and future UI reporting.

Source§

impl Keymap

Source

pub fn shortcut_for_command( &self, ctx: &InputContext, command: &CommandId, ) -> Option<KeyChord>

Best-effort reverse lookup for UI display (command palette / menus).

This applies the same platform + when matching rules as resolve, then finds any chord whose effective command equals command under the provided context.

Source

pub fn shortcut_for_command_sequence( &self, ctx: &InputContext, command: &CommandId, ) -> Option<Vec<KeyChord>>

Source

pub fn shortcut_for_command_sequence_with_key_contexts( &self, ctx: &InputContext, key_contexts: &[Arc<str>], command: &CommandId, ) -> Option<Vec<KeyChord>>

Source

pub fn display_shortcut_for_command( &self, base: &InputContext, command: &CommandId, ) -> Option<KeyChord>

Best-effort reverse lookup for UI display that is intentionally stable across focus changes.

This is intended for menu bar / command palette shortcut labels, where displaying different shortcuts as focus moves is confusing. Instead of using the live focus state, we evaluate bindings against a small set of “default” contexts derived from base:

  • non-modal + not text input
  • non-modal + text input
  • modal + not text input
  • modal + text input

Candidate sequences are ranked by:

  1. first matching default context (earlier is preferred),
  2. shorter sequences (single-chord preferred),
  3. later-defined bindings (user/project overrides preferred).
Source

pub fn display_shortcut_for_command_sequence( &self, base: &InputContext, command: &CommandId, ) -> Option<Vec<KeyChord>>

Source

pub fn display_shortcut_for_command_sequence_with_key_contexts( &self, base: &InputContext, key_contexts: &[Arc<str>], command: &CommandId, ) -> Option<Vec<KeyChord>>

Source§

impl Keymap

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, KeymapError>

Source

pub fn from_bytes_with_options( bytes: &[u8], options: KeymapLoadOptions, ) -> Result<Self, KeymapError>

Source

pub fn from_v1(file: KeymapFileV1) -> Result<Self, KeymapError>

Source

pub fn from_v1_with_options( file: KeymapFileV1, options: KeymapLoadOptions, ) -> Result<Self, KeymapError>

Source§

impl Keymap

Source

pub fn empty() -> Self

Source

pub fn push_binding(&mut self, binding: Binding)

Source

pub fn resolve(&self, ctx: &InputContext, chord: KeyChord) -> Option<CommandId>

Last-wins resolution. If a later binding matches and its command is None, the key is explicitly unbound and resolution stops.

Source

pub fn resolve_with_key_contexts( &self, ctx: &InputContext, key_contexts: &[Arc<str>], chord: KeyChord, ) -> Option<CommandId>

Like Self::resolve, but evaluates when expressions with a key-context stack.

Source

pub fn match_sequence( &self, ctx: &InputContext, sequence: &[KeyChord], ) -> SequenceMatch

Sequence matching helper used by pending multi-stroke bindings (ADR 0043).

Source

pub fn match_sequence_with_key_contexts( &self, ctx: &InputContext, key_contexts: &[Arc<str>], sequence: &[KeyChord], ) -> SequenceMatch

Like Self::match_sequence, but evaluates when expressions with a key-context stack.

Source

pub fn continuations( &self, ctx: &InputContext, prefix: &[KeyChord], ) -> Vec<KeymapContinuation>

Lists the valid “next” keystrokes that can follow the provided prefix under the given input context.

This is intended for UI hint overlays (e.g. a leader-key popup): it enumerates candidate next chords from the configured bindings, then uses match_sequence to filter down to chords that either execute a command or have further continuations.

Source

pub fn continuations_with_key_contexts( &self, ctx: &InputContext, key_contexts: &[Arc<str>], prefix: &[KeyChord], ) -> Vec<KeymapContinuation>

Like Self::continuations, but evaluates when expressions with a key-context stack.

Source

pub fn extend(&mut self, other: Keymap)

Trait Implementations§

Source§

impl Clone for Keymap

Source§

fn clone(&self) -> Keymap

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 Keymap

Source§

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

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

impl Default for Keymap

Source§

fn default() -> Keymap

Returns the “default value” for a type. 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 = 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.