From f336f8e28cc0b20cfd47016b5797856cce4bfdd4 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Thu, 5 Nov 2026 12:56:36 -0500 Subject: [PATCH] Select and Mask E test: through handle(), with and without a focused text field (#11402) Two tests send a bare E through the shortcut handler with Select and Mask open. With a text field focused the mode stays, and without one the mode flips, so the text-edit gate in handle() is covered. Co-Authored-By: Claude Fable 5.1 --- .../select_mask_ui/cycle_tool_mode_tests.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs index 94843aaffcc..24deb4e4ab0 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs @@ -111,3 +111,43 @@ fn a_polygon_in_progress_keeps_its_starting_mode() { assert!(!ws(&app).add); assert_eq!(ws(&app).poly.as_ref().map(|(a, _)| *a), Some(true)); } + +fn e_event() -> egui::RawInput { + let ev = egui::Event::Key { key: Key::E, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; + egui::RawInput { events: vec![ev], ..Default::default() } +} + +/// Through the shortcut handler, as the app runs it: a focused text field keeps the E. +#[test] +fn e_through_handle_is_ignored_while_a_text_field_has_focus() { + let mut app = opened(); + let ctx = egui::Context::default(); + let mut text = String::new(); + ctx.run_ui(Default::default(), |ui| { + ui.text_edit_singleline(&mut text).request_focus(); + }) + .textures_delta + .clear(); + ctx.run_ui(e_event(), |ui| { + assert!(ui.ctx().text_edit_focused()); + crate::shortcuts::handle(&mut app, ui.ctx()); + ui.text_edit_singleline(&mut text); + }) + .textures_delta + .clear(); + assert!(ws(&app).add); +} + +/// The same path with no text field focused: E flips the mode. +#[test] +fn e_through_handle_flips_the_mode_without_a_focused_text_field() { + let mut app = opened(); + let ctx = egui::Context::default(); + ctx.run_ui(e_event(), |ui| { + assert!(!ui.ctx().text_edit_focused()); + crate::shortcuts::handle(&mut app, ui.ctx()); + }) + .textures_delta + .clear(); + assert!(!ws(&app).add); +}