pub enum KeyBindingContextPredicate {
Identifier(SharedString),
Equal(SharedString, SharedString),
NotEqual(SharedString, SharedString),
Descendant(Box<KeyBindingContextPredicate>, Box<KeyBindingContextPredicate>),
Not(Box<KeyBindingContextPredicate>),
And(Box<KeyBindingContextPredicate>, Box<KeyBindingContextPredicate>),
Or(Box<KeyBindingContextPredicate>, Box<KeyBindingContextPredicate>),
}Expand description
A condition on the key context stack that decides whether a binding applies.
A predicate is written in a small language, such as Editor && mode == insert, and is
evaluated against the KeyContexts on the focus path. Build one with
KeyBindingContextPredicate::parse.
Display writes the predicate in the same syntax. It adds parentheses around || inside &&
and around negated groups. Descendant expressions are written without parentheses around their
operands, so add parentheses yourself when combining > with && or || in text that must
round-trip through parse.
§Examples
let predicate = KeyBindingContextPredicate::parse("Editor && mode == insert").unwrap();
assert_eq!(predicate.to_string(), "Editor && mode == insert");
let stack = [
KeyContext::parse("Workspace").unwrap(),
KeyContext::parse("Editor mode=insert").unwrap(),
];
assert_eq!(predicate.depth_of(&stack), Some(2));Variants§
Identifier(SharedString)
Matches a context that has an entry named by the identifier, with or without a value.
Equal(SharedString, SharedString)
Matches a context whose entry for the key has the given value. Written key == value.
NotEqual(SharedString, SharedString)
Matches unless the context’s entry for the key has the given value. Written key != value.
Also matches when the context has no entry for the key.
Descendant(Box<KeyBindingContextPredicate>, Box<KeyBindingContextPredicate>)
Matches when the first predicate matches an ancestor context and the second matches the
contexts beneath it. Written parent > child.
Not(Box<KeyBindingContextPredicate>)
Matches when the inner predicate doesn’t match. Written !inner.
And(Box<KeyBindingContextPredicate>, Box<KeyBindingContextPredicate>)
Matches when both predicates match. Written left && right.
Or(Box<KeyBindingContextPredicate>, Box<KeyBindingContextPredicate>)
Matches when either predicate matches. Written left || right.
Implementations§
Source§impl KeyBindingContextPredicate
impl KeyBindingContextPredicate
Sourcepub fn parse(source: &str) -> Result<Self>
pub fn parse(source: &str) -> Result<Self>
Parses a predicate such as Editor && !ReadOnly or Panel > Editor.
The grammar, from the tightest-binding rule to the loosest, is:
- Atoms. An identifier, such as
Editor, matches a context with that name. An identifier is letters, digits,_and-. The characters>,<,~,"and?can also appear after the first character, so writePanel > Editorwith spaces. The textPanel>Editoris one identifier. - Parentheses.
( ... )groups a predicate. - Negation.
!applies to the atom or parenthesized group after it, so!a && bis(!a) && b. Use!(a && b)to negate a group. - Equality.
key == valueandkey != valuecompare the value of an entry. Both sides must be plain identifiers, somode == "full"is an error. &&binds tighter than||. Soa || b && cisa || (b && c).- Descendant.
parent > childbinds loosest, soa && b > cis(a && b) > c. It is left-associative:A > B > Cis(A > B) > C.
The keymap guide has the same rules as a table.
§Errors
Returns an error for an unbalanced parenthesis, a missing operand, an operator the grammar
doesn’t have, a == or != whose operands aren’t identifiers, or any leftover text.
§Examples
let predicate = KeyBindingContextPredicate::parse("Pane > (Editor || Terminal) && !ReadOnly")
.unwrap();
assert_eq!(predicate.to_string(), "Pane > (Editor || Terminal) && !ReadOnly");
assert!(KeyBindingContextPredicate::parse("mode == \"full\"").is_err());See contexts and keyboard input for when contexts apply.
Sourcepub fn depth_of(&self, contexts: &[KeyContext]) -> Option<usize>
pub fn depth_of(&self, contexts: &[KeyContext]) -> Option<usize>
Returns the deepest depth at which the predicate matches contexts, or None if it
matches none.
A depth d means the predicate matches the first d contexts, with the dth as the
deepest one that identifiers and == look at. The keymap uses this depth to rank bindings:
a deeper match wins. A predicate that matches only at a shallower depth is returned at that
depth.
§Examples
let predicate = KeyBindingContextPredicate::parse("Workspace").unwrap();
let stack = [
KeyContext::parse("Workspace").unwrap(),
KeyContext::parse("Editor").unwrap(),
];
assert_eq!(predicate.depth_of(&stack), Some(1));
assert_eq!(predicate.depth_of(&stack[1..]), None);Sourcepub fn eval(&self, contexts: &[KeyContext]) -> bool
pub fn eval(&self, contexts: &[KeyContext]) -> bool
Returns whether the predicate matches the whole of contexts, which is ordered from the
root to the focused element.
Sourcepub fn eval_inner(
&self,
contexts: &[KeyContext],
all_contexts: &[KeyContext],
) -> bool
pub fn eval_inner( &self, contexts: &[KeyContext], all_contexts: &[KeyContext], ) -> bool
Sourcepub fn is_superset(&self, other: &Self) -> bool
pub fn is_superset(&self, other: &Self) -> bool
Returns whether every context that other matches is also matched by self.
The check is conservative. true is certain, but false means only that this check
couldn’t show it. The keymap uses it to check whether a disabling binding’s context covers
the context of the binding it disables.
§Examples
let editor = KeyBindingContextPredicate::parse("Editor").unwrap();
let editor_and_vim = KeyBindingContextPredicate::parse("Editor && vim_mode").unwrap();
assert!(editor.is_superset(&editor_and_vim));
assert!(!editor_and_vim.is_superset(&editor));Trait Implementations§
Source§impl Clone for KeyBindingContextPredicate
impl Clone for KeyBindingContextPredicate
Source§impl Debug for KeyBindingContextPredicate
impl Debug for KeyBindingContextPredicate
Source§impl Display for KeyBindingContextPredicate
impl Display for KeyBindingContextPredicate
impl Eq for KeyBindingContextPredicate
Source§impl Hash for KeyBindingContextPredicate
impl Hash for KeyBindingContextPredicate
impl StructuralPartialEq for KeyBindingContextPredicate
Auto Trait Implementations§
impl Freeze for KeyBindingContextPredicate
impl RefUnwindSafe for KeyBindingContextPredicate
impl Send for KeyBindingContextPredicate
impl Sync for KeyBindingContextPredicate
impl Unpin for KeyBindingContextPredicate
impl UnsafeUnpin for KeyBindingContextPredicate
impl UnwindSafe for KeyBindingContextPredicate
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more