From b9a8fa304cbb064607941e0b0da0f8ca02416f43 Mon Sep 17 00:00:00 2001 From: prxnvt <53838599+prxnvt@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:22:13 -0400 Subject: [PATCH] UI: Change in the macro step editor picks only the commands its list shows In Change mode the picker hid the Repeat, If and Stop rows but still indexed the full list, so Enter with an empty search (index 0, nothing highlighted) picked Repeat and turned the command step into a Repeat step; a search for "if" or "stop" did the same. The control rows are now dropped from the list before it is indexed, drawn or chosen. --- crates/ui-egui/src/macro_editor.rs | 9 +++++---- crates/ui-egui/tests/it/macro_editor.rs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/macro_editor.rs b/crates/ui-egui/src/macro_editor.rs index 40d6118a4..8c3cf76db 100644 --- a/crates/ui-egui/src/macro_editor.rs +++ b/crates/ui-egui/src/macro_editor.rs @@ -1344,7 +1344,11 @@ fn picker(ui: &mut Ui, ed: &mut Editor) { if r.changed() { pk.index = 0; } - let items = picker_items(&pk.search); + let mut items = picker_items(&pk.search); + // Change swaps a command step's command; it can't turn the step into Repeat, If or Stop. + if pk.replace.is_some() { + items.retain(|(id, ..)| !id.starts_with('@')); + } if ui.input(|i| i.key_pressed(egui::Key::ArrowDown)) { pk.index = (pk.index + 1).min(items.len().saturating_sub(1)); } @@ -1354,9 +1358,6 @@ fn picker(ui: &mut Ui, ed: &mut Editor) { let mut chosen = ui.input(|i| i.key_pressed(egui::Key::Enter)).then_some(pk.index); egui::ScrollArea::vertical().id_salt("me_pick_list").auto_shrink([false, false]).show(ui, |ui| { for (i, (id, label, menu)) in items.iter().enumerate() { - if pk.replace.is_some() && id.starts_with('@') { - continue; - } let r = ui.add(egui::Button::selectable(i == pk.index, label.as_str()).min_size(vec2(ui.available_width(), 20.0))); if r.clicked() { chosen = Some(i); diff --git a/crates/ui-egui/tests/it/macro_editor.rs b/crates/ui-egui/tests/it/macro_editor.rs index 8c3b07cc1..c302f9bb4 100644 --- a/crates/ui-egui/tests/it/macro_editor.rs +++ b/crates/ui-egui/tests/it/macro_editor.rs @@ -285,3 +285,23 @@ fn another_dialog_never_replaces_the_open_editor() { click(&mut h, "New Macro"); assert_eq!(h.state().macros.editor.as_ref().map(|e| e.draft.name.as_str()), Some("Unsaved")); } + +#[test] +fn enter_in_change_never_picks_a_control_step() { + let mut h = harness(); + three(&mut h); + let enter = Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; + for search in ["", "stop"] { + h.state_mut().macros.editor.as_mut().unwrap().selected = Some("1".into()); + h.run_steps(2); + click(&mut h, "Change…"); + if !search.is_empty() { + h.input_mut().events.push(Event::Text(search.into())); + h.run_steps(2); + } + h.input_mut().events.push(enter.clone()); + h.run_steps(3); + let ed = h.state().macros.editor.as_ref().unwrap(); + assert!(matches!(&ed.draft.steps[0].kind, StepKind::Command { .. }), "{search:?}: {:?}", ed.draft.steps[0].kind); + } +}