From 00afd27dcadb5985f1c9d8518c7c8a4e1ae9f8f9 Mon Sep 17 00:00:00 2001 From: pravdomil <2387356+pravdomil@users.noreply.github.com> Date: Mon, 12 Oct 2026 21:42:40 +0200 Subject: [PATCH] Keyboard Shortcuts: Enter is OK [skip ci] Enter closes the editor like its OK button, also while the search field has focus. It stays with the shortcut recorder (Enter can be recorded), the preset rename field and an open preset menu. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panels/shortcut_editor.rs | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/ui-egui/src/panels/shortcut_editor.rs b/crates/ui-egui/src/panels/shortcut_editor.rs index f12fe4ef..b0e3d7f2 100644 --- a/crates/ui-egui/src/panels/shortcut_editor.rs +++ b/crates/ui-egui/src/panels/shortcut_editor.rs @@ -215,6 +215,9 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) { } } } + // Enter is OK, unless it belongs to the rename field or an open preset menu. A recorded Enter + // never gets here: the recorder took the frame's key events above. + close |= st.rename.is_none() && !egui::Popup::is_any_open(ctx) && ctx.input(|i| i.modifiers.is_none() && i.key_pressed(egui::Key::Enter)); // Modifiers: toggles, or the ones held on the keyboard. let held = ctx.input(|i| i.modifiers); let held = [held.ctrl && cfg!(target_os = "macos"), held.command, held.alt, held.shift]; @@ -631,6 +634,29 @@ mod tests { } } + #[test] + fn enter_is_ok_except_while_recording_or_renaming() { + let enter = || egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + let mut app = EffectcraftApp::new(effectcraft_engine::Session::default()); + let ctx = egui::Context::default(); + crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app)); + // Recording: Enter is the recorded key. + open(&mut app); + app.dialog_state.shortcuts.recording = true; + frame(&mut app, &ctx, vec![enter()]); + assert_eq!(app.dialog, Some(Dialog::Shortcuts)); + assert_eq!(app.dialog_state.shortcuts.pending, "Enter"); + // Renaming a preset: Enter belongs to the name field. + app.dialog_state.shortcuts.rename = Some("Mine".into()); + frame(&mut app, &ctx, vec![enter()]); + assert_eq!(app.dialog, Some(Dialog::Shortcuts)); + // Otherwise it closes the editor, also with the search field focused. + app.dialog_state.shortcuts.rename = None; + frame(&mut app, &ctx, vec![]); + frame(&mut app, &ctx, vec![enter()]); + assert_eq!(app.dialog, None); + } + #[test] fn recording_a_shortcut_does_not_also_type_the_key_into_the_field() { let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());