mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Help › Search: ← / → and Space edit the field instead of driving the menu
While a text field in an open menu has the keyboard, Nav::keys leaves ← / → (cursor) and Space (a typed space) to it: ← / → no longer switch Help to Window / File, and Space no longer runs the lit result. ↑ / ↓, ↩ and Esc are unchanged. Follow-up to #5996 / #6030 (letters). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c11ef015b7
commit
a008842a85
2 files changed
+41
-1
No files matched your search
@@ -336,7 +336,12 @@ impl Nav {
|
||||
let Some(top) = self.top.filter(|_| !tops.is_empty()) else { return };
|
||||
let level = self.level.min(self.rows.len().saturating_sub(1));
|
||||
self.level = level;
|
||||
let press = |k: Key| ctx.input_mut(|i| i.consume_key(Modifiers::NONE, k));
|
||||
// A text field in the menu (Help › Search) keeps the keys that edit it: ← / → move its
|
||||
// cursor and Space types a space.
|
||||
let typing = ctx.text_edit_focused();
|
||||
let press = |k: Key| {
|
||||
!(typing && matches!(k, Key::ArrowLeft | Key::ArrowRight | Key::Space)) && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, k))
|
||||
};
|
||||
let current = self.highlighted(level).and_then(|i| self.rows.get(level)?.get(i)).cloned();
|
||||
let switch = |by: usize| {
|
||||
let n = tops.len();
|
||||
|
||||
@@ -265,6 +265,41 @@ fn left_and_right_switch_menus_and_shortcuts_wait_while_one_is_open() {
|
||||
assert!(!is_open(&h.ctx), "shortcuts work again");
|
||||
}
|
||||
|
||||
/// In Help › Search, ← / → move the field's cursor instead of switching to Window / File, and
|
||||
/// Space types a space instead of running the lit row.
|
||||
#[test]
|
||||
fn help_search_keeps_the_arrows_and_space_that_edit_it() {
|
||||
let mut h = harness((1280.0, 720.0, 1.0));
|
||||
open(&mut h, "Help");
|
||||
let field = egui::Id::new("help-menu-search").with("field");
|
||||
assert_eq!(h.ctx.memory(|m| m.focused()), Some(field), "the search field has the keyboard");
|
||||
let text = |h: &Harness<'static, PhotocraftApp>| h.ctx.data(|d| d.get_temp::<String>(egui::Id::new("help-menu-search"))).unwrap_or_default();
|
||||
let typing = |h: &mut Harness<'static, PhotocraftApp>, s: &str| {
|
||||
h.event(egui::Event::Text(s.to_string()));
|
||||
h.run_steps(3);
|
||||
};
|
||||
typing(&mut h, "levls");
|
||||
key(&mut h, egui::Key::ArrowLeft);
|
||||
assert!(h.query_by_label_contains("About PhotoCraft").is_some(), "← keeps Help open");
|
||||
key(&mut h, egui::Key::ArrowLeft);
|
||||
typing(&mut h, "e");
|
||||
assert_eq!(text(&h), "levels", "← moved the cursor");
|
||||
key(&mut h, egui::Key::ArrowRight);
|
||||
assert!(h.query_by_label_contains("About PhotoCraft").is_some(), "→ keeps Help open");
|
||||
// The pointer resting on a result lights it; a space typed then is text, not a click.
|
||||
let levels = h.get_by_label_contains("› Levels").rect().center();
|
||||
h.hover_at(levels);
|
||||
h.run_steps(3);
|
||||
assert!(Nav::current(&h.ctx).highlighted(0).is_some(), "a result is lit");
|
||||
h.event(egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE });
|
||||
h.event(egui::Event::Text(" ".into()));
|
||||
h.event(egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
assert!(is_open(&h.ctx) && h.query_by_label_contains("About PhotoCraft").is_some(), "Space keeps Help open");
|
||||
assert!(h.state().ui.dialogs.is_empty(), "Space ran no command: {:?}", h.state().ui.dialogs);
|
||||
assert_eq!(text(&h), "levels ");
|
||||
}
|
||||
|
||||
/// A level's visible height (its view) and the full height of its rows: equal means no scrolling.
|
||||
fn fits(h: &Harness<'static, PhotocraftApp>, level: usize) -> (f32, f32) {
|
||||
let nav = Nav::current(&h.ctx);
|
||||
|
||||
Reference in new issue
Block a user