mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 18:46:49 +00:00
Merge pull request #545 from zed-industries/halt-global-actions
Halt keystroke dispatch when a global action is dispatched
This commit is contained in:
commit
00ba5dffa5
1 changed files with 34 additions and 11 deletions
|
@ -1239,7 +1239,7 @@ impl MutableAppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !this.halt_action_dispatch {
|
if !this.halt_action_dispatch {
|
||||||
this.dispatch_global_action_any(action);
|
this.halt_action_dispatch = this.dispatch_global_action_any(action);
|
||||||
}
|
}
|
||||||
this.halt_action_dispatch
|
this.halt_action_dispatch
|
||||||
})
|
})
|
||||||
|
@ -4716,8 +4716,6 @@ mod tests {
|
||||||
|
|
||||||
#[crate::test(self)]
|
#[crate::test(self)]
|
||||||
fn test_dispatch_keystroke(cx: &mut MutableAppContext) {
|
fn test_dispatch_keystroke(cx: &mut MutableAppContext) {
|
||||||
use std::cell::Cell;
|
|
||||||
|
|
||||||
action!(Action, &'static str);
|
action!(Action, &'static str);
|
||||||
|
|
||||||
struct View {
|
struct View {
|
||||||
|
@ -4774,13 +4772,28 @@ mod tests {
|
||||||
Some("a && b && !c"),
|
Some("a && b && !c"),
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let handled_action = Rc::new(Cell::new(false));
|
cx.add_bindings(vec![keymap::Binding::new("b", Action("b"), None)]);
|
||||||
let handled_action_clone = handled_action.clone();
|
|
||||||
cx.add_action(move |view: &mut View, action: &Action, _| {
|
let actions = Rc::new(RefCell::new(Vec::new()));
|
||||||
handled_action_clone.set(true);
|
{
|
||||||
assert_eq!(view.id, 2);
|
let actions = actions.clone();
|
||||||
assert_eq!(action.0, "a");
|
cx.add_action(move |view: &mut View, action: &Action, cx| {
|
||||||
|
if action.0 == "a" {
|
||||||
|
actions.borrow_mut().push(format!("{} a", view.id));
|
||||||
|
} else {
|
||||||
|
actions
|
||||||
|
.borrow_mut()
|
||||||
|
.push(format!("{} {}", view.id, action.0));
|
||||||
|
cx.propagate_action();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let actions = actions.clone();
|
||||||
|
cx.add_global_action(move |action: &Action, _| {
|
||||||
|
actions.borrow_mut().push(format!("global {}", action.0));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
cx.dispatch_keystroke(
|
cx.dispatch_keystroke(
|
||||||
window_id,
|
window_id,
|
||||||
|
@ -4789,7 +4802,17 @@ mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(handled_action.get());
|
assert_eq!(&*actions.borrow(), &["2 a"]);
|
||||||
|
|
||||||
|
actions.borrow_mut().clear();
|
||||||
|
cx.dispatch_keystroke(
|
||||||
|
window_id,
|
||||||
|
vec![view_1.id(), view_2.id(), view_3.id()],
|
||||||
|
&Keystroke::parse("b").unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(&*actions.borrow(), &["3 b", "2 b", "1 b", "global b"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::test(self)]
|
#[crate::test(self)]
|
||||||
|
|
Loading…
Reference in a new issue