Verify keystrokes can be queried while views are on the stack
This commit is contained in:
parent
3d679ddb26
commit
5cc6304fa6
1 changed files with 59 additions and 53 deletions
|
@ -5678,7 +5678,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::test(self)]
|
#[crate::test(self)]
|
||||||
fn test_keystrokes_for_action(cx: &mut AppContext) {
|
fn test_keystrokes_for_action(cx: &mut TestAppContext) {
|
||||||
actions!(test, [Action1, Action2, GlobalAction]);
|
actions!(test, [Action1, Action2, GlobalAction]);
|
||||||
|
|
||||||
struct View1 {}
|
struct View1 {}
|
||||||
|
@ -5708,12 +5708,13 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (window_id, view_1) = cx.add_window(Default::default(), |_| View1 {});
|
let (_, view_1) = cx.add_window(|_| View1 {});
|
||||||
let view_2 = cx.add_view(&view_1, |cx| {
|
let view_2 = cx.add_view(&view_1, |cx| {
|
||||||
cx.focus_self();
|
cx.focus_self();
|
||||||
View2 {}
|
View2 {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cx.update(|cx| {
|
||||||
cx.add_action(|_: &mut View1, _: &Action1, _cx| {});
|
cx.add_action(|_: &mut View1, _: &Action1, _cx| {});
|
||||||
cx.add_action(|_: &mut View2, _: &Action2, _cx| {});
|
cx.add_action(|_: &mut View2, _: &Action2, _cx| {});
|
||||||
cx.add_global_action(|_: &GlobalAction, _| {});
|
cx.add_global_action(|_: &GlobalAction, _| {});
|
||||||
|
@ -5723,8 +5724,12 @@ mod tests {
|
||||||
Binding::new("b", Action2, Some("View1 > View2")),
|
Binding::new("b", Action2, Some("View1 > View2")),
|
||||||
Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist
|
Binding::new("c", GlobalAction, Some("View3")), // View 3 does not exist
|
||||||
]);
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
cx.update_window(window_id, |cx| {
|
// Here we update the views to ensure that, even if they are on the stack,
|
||||||
|
// we can still retrieve keystrokes correctly.
|
||||||
|
view_1.update(cx, |_, cx| {
|
||||||
|
view_2.update(cx, |_, cx| {
|
||||||
// Sanity check
|
// Sanity check
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cx.keystrokes_for_action(view_1.id(), &Action1)
|
cx.keystrokes_for_action(view_1.id(), &Action1)
|
||||||
|
@ -5773,6 +5778,7 @@ mod tests {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Produces a list of actions and key bindings
|
// Produces a list of actions and key bindings
|
||||||
fn available_actions(
|
fn available_actions(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue