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.
This commit is contained in:
prxnvt
2026-10-25 06:48:57 -04:00
parent c523a4c48a
commit b9a8fa304c
2 changed files with 25 additions and 4 deletions
+5 -4
View File
@@ -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);
+20
View File
@@ -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);
}
}