Unbind app menu actions (#20268)

Closes #7544

Release Notes:

- Fixed an issue that prevented removing key bindings for actions used
in the macOS application menu.
This commit is contained in:
Max Brunsfeld 2024-11-05 16:18:41 -08:00 committed by GitHub
parent b23835b5a5
commit 50069a2153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 126 additions and 13 deletions

View file

@ -269,6 +269,30 @@ impl KeyBindingContextPredicate {
}
}
/// Returns whether or not this predicate matches all possible contexts matched by
/// the other predicate.
pub fn is_superset(&self, other: &Self) -> bool {
if self == other {
return true;
}
if let KeyBindingContextPredicate::Or(left, right) = self {
return left.is_superset(other) || right.is_superset(other);
}
match other {
KeyBindingContextPredicate::Child(_, child) => self.is_superset(child),
KeyBindingContextPredicate::And(left, right) => {
self.is_superset(left) || self.is_superset(right)
}
KeyBindingContextPredicate::Identifier(_) => false,
KeyBindingContextPredicate::Equal(_, _) => false,
KeyBindingContextPredicate::NotEqual(_, _) => false,
KeyBindingContextPredicate::Not(_) => false,
KeyBindingContextPredicate::Or(_, _) => false,
}
}
fn parse_expr(mut source: &str, min_precedence: u32) -> anyhow::Result<(Self, &str)> {
type Op = fn(
KeyBindingContextPredicate,
@ -559,4 +583,27 @@ mod tests {
)
);
}
#[test]
fn test_is_superset() {
assert_is_superset("editor", "editor", true);
assert_is_superset("editor", "workspace", false);
assert_is_superset("editor", "editor && vim_mode", true);
assert_is_superset("editor", "mode == full && editor", true);
assert_is_superset("editor && mode == full", "editor", false);
assert_is_superset("editor", "something > editor", true);
assert_is_superset("editor", "editor > menu", false);
assert_is_superset("foo || bar || baz", "bar", true);
assert_is_superset("foo || bar || baz", "quux", false);
#[track_caller]
fn assert_is_superset(a: &str, b: &str, result: bool) {
let a = KeyBindingContextPredicate::parse(a).unwrap();
let b = KeyBindingContextPredicate::parse(b).unwrap();
assert_eq!(a.is_superset(&b), result, "({a:?}).is_superset({b:?})");
}
}
}