Switch from changing the meaning of the predicate to adding an additional match_dispatch_path_context API for UI elements
This commit is contained in:
parent
0384456e7d
commit
9dc608dc4b
3 changed files with 12 additions and 9 deletions
|
@ -1248,7 +1248,7 @@ impl MutableAppContext {
|
||||||
self.keystroke_matcher
|
self.keystroke_matcher
|
||||||
.bindings_for_action_type(action.as_any().type_id())
|
.bindings_for_action_type(action.as_any().type_id())
|
||||||
.find_map(|b| {
|
.find_map(|b| {
|
||||||
if b.match_context(&contexts) {
|
if b.match_dispatch_path_context(&contexts) {
|
||||||
Some(b.keystrokes().into())
|
Some(b.keystrokes().into())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -1283,7 +1283,7 @@ impl MutableAppContext {
|
||||||
deserialize("{}").ok()?,
|
deserialize("{}").ok()?,
|
||||||
self.keystroke_matcher
|
self.keystroke_matcher
|
||||||
.bindings_for_action_type(*type_id)
|
.bindings_for_action_type(*type_id)
|
||||||
.filter(|b| b.match_context(&contexts))
|
.filter(|b| b.match_dispatch_path_context(&contexts))
|
||||||
.collect(),
|
.collect(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,6 +42,15 @@ impl Binding {
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn match_dispatch_path_context(&self, contexts: &[KeymapContext]) -> bool {
|
||||||
|
for i in 0..contexts.len() {
|
||||||
|
if self.match_context(&contexts[i..]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
pub fn match_keys_and_context(
|
pub fn match_keys_and_context(
|
||||||
&self,
|
&self,
|
||||||
pending_keystrokes: &Vec<Keystroke>,
|
pending_keystrokes: &Vec<Keystroke>,
|
||||||
|
|
|
@ -64,13 +64,7 @@ impl KeymapContextPredicate {
|
||||||
pub fn eval(&self, contexts: &[KeymapContext]) -> bool {
|
pub fn eval(&self, contexts: &[KeymapContext]) -> bool {
|
||||||
let Some(context) = contexts.first() else { return false };
|
let Some(context) = contexts.first() else { return false };
|
||||||
match self {
|
match self {
|
||||||
Self::Identifier(name) => {
|
Self::Identifier(name) => (&context.set).contains(name.as_str()),
|
||||||
if (&context.set).contains(name.as_str()) {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
self.eval(&contexts[1..])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Self::Equal(left, right) => context
|
Self::Equal(left, right) => context
|
||||||
.map
|
.map
|
||||||
.get(left.as_str())
|
.get(left.as_str())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue