diff --git a/src/runtime/Stage.cpp b/src/runtime/Stage.cpp index c74b86b..7ba51e8 100644 --- a/src/runtime/Stage.cpp +++ b/src/runtime/Stage.cpp @@ -383,6 +383,11 @@ auto Stage::match_input(bool first_iteration, if (no_might_match_mapping && (!first_iteration || m_history.empty())) continue; + // no-might-match mappings are matched only + // when current event comes from a device + if (no_might_match_mapping && (device_index == any_device_index)) + continue; + // might match is only accepted in first iteration (whole sequence) const auto accept_might_match = (first_iteration && !no_might_match_mapping); diff --git a/src/test/test4_Server.cpp b/src/test/test4_Server.cpp index 16b7ce3..5ac8d31 100644 --- a/src/test/test4_Server.cpp +++ b/src/test/test4_Server.cpp @@ -152,6 +152,22 @@ TEST_CASE("Minimal configuration", "[Server]") { CHECK(state.apply_input("-A") == "-B"); } + +//-------------------------------------------------------------------- + +TEST_CASE("Modifier filter and no might match (infinite loop bug)", "[Server]") { + auto state = create_state(R"( + ContextActive >> Virtual1 + + [modifier = Virtual1] + ? X >> A Virtual1 + )"); + CHECK(state.apply_input("+X") == "+A -A"); + CHECK(state.apply_input("-X") == ""); + CHECK(state.apply_input("+X") == "+X"); + CHECK(state.apply_input("-X") == "-X"); +} + //-------------------------------------------------------------------- TEST_CASE("Trigger Not Timeout", "[Server]") {