diff --git a/crates/benilla-app/src/bindings.rs b/crates/benilla-app/src/bindings.rs index eb2e5c8b..fc5c3d02 100644 --- a/crates/benilla-app/src/bindings.rs +++ b/crates/benilla-app/src/bindings.rs @@ -899,6 +899,52 @@ mod tests { .expect("eval") } + /// A **chorded** registry `EdgeUpDown` runs both halves, which is what an action button on a + /// modified key is. + /// + /// grom's slam macro sits on `SHIFT-1` → `MULTIACTIONBAR1BUTTON1` + /// (`bindings/C_Thun-Gromgosh.txt:28`), and pfUI points both `MultiActionButtonDown` and + /// `MultiActionButtonUp` at the same `pfActionButton` (`modules/actionbar.lua:1516-17`), so + /// the reference runs his macro twice per press — once on the press, once on the release — + /// and he reported seeing it run once. Both halves have to reach the VM for that second roll + /// at a 0.2 s window to exist. + #[test] + fn a_chorded_action_button_runs_both_halves() { + let mut script = UiScript::new().expect("VM"); + script.register_bindings(®istry_commands()); + script + .run( + "MULTI_DOWN = 0 MULTI_UP = 0 \ + function MultiActionButtonDown() MULTI_DOWN = MULTI_DOWN + 1 end \ + function MultiActionButtonUp() MULTI_UP = MULTI_UP + 1 end \ + SetBinding(\"SHIFT-1\", \"MULTIACTIONBAR1BUTTON1\")", + ) + .expect("bind"); + let mut app = vm_harness(script); + + // The modifier is held across both edges, as a hand holding shift is. + press_key(&mut app, KeyCode::ShiftLeft); + app.update(); + + press_key(&mut app, KeyCode::Digit1); + app.update(); + assert_eq!(lua_count(&app, "MULTI_DOWN"), 1, "the press half"); + assert_eq!(lua_count(&app, "MULTI_UP"), 0, "not released yet"); + + release_key(&mut app, KeyCode::Digit1); + app.update(); + assert_eq!( + lua_count(&app, "MULTI_UP"), + 1, + "the release half — the second evaluation of the macro" + ); + assert_eq!( + lua_count(&app, "MULTI_DOWN"), + 1, + "and not the down half again" + ); + } + /// An addon's `runOnUp` body is one chunk run twice, `keystate` "down" then "up"; our own /// registry holds two strings ([`Kind::EdgeUpDown`]) instead. #[test]