Skip to content

Commit

Permalink
Keep key held when pressed immediately after !Any
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Aug 7, 2024
1 parent 283a4cb commit 6ccfb55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/runtime/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,15 @@ void Stage::update_output(const KeyEvent& event, const Trigger& trigger, int con
if (output.key == event.key)
return;
}
else if (output.temporarily_released &&
output.key == event.key &&
!m_output_buffer.empty() &&
m_output_buffer.back() == KeyEvent(event.key, KeyState::Up)) {
// when it was the last output, simply undo releasing
m_output_buffer.pop_back();
output.temporarily_released = false;
return;
}

if (it == end(m_output_down)) {
if (event.key != Key::timeout)
Expand Down
17 changes: 8 additions & 9 deletions src/test/test3_Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ TEST_CASE("Not Any in output", "[Stage]") {
CHECK(format_sequence(stage.sequence()) == "#ShiftLeft");
CHECK(apply_input(stage, "+X") == "-ShiftLeft +1");
CHECK(format_sequence(stage.sequence()) == "#ShiftLeft #X");
CHECK(apply_input(stage, "+X") == "-1 +1");
CHECK(apply_input(stage, "+X") == "-1 +1");
CHECK(apply_input(stage, "+X") == "");
CHECK(apply_input(stage, "+X") == "");
CHECK(apply_input(stage, "-X") == "-1");
CHECK(apply_input(stage, "-ShiftLeft") == "");
REQUIRE(stage.is_clear());
Expand Down Expand Up @@ -2667,8 +2667,7 @@ TEST_CASE("Explicit modifier", "[Stage]") {
REQUIRE(stage.is_clear());

REQUIRE(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
// that the Shift is released and pressed at the beginning is also not ideal
REQUIRE(apply_input(stage, "+C") == "-ShiftLeft +ShiftLeft +G -G -ShiftLeft +H -H");
REQUIRE(apply_input(stage, "+C") == "+G -G -ShiftLeft +H -H");
REQUIRE(apply_input(stage, "-C") == "");
REQUIRE(apply_input(stage, "+C") == "+ShiftLeft +G -G -ShiftLeft +H -H");
REQUIRE(apply_input(stage, "-C") == "");
Expand All @@ -2679,7 +2678,7 @@ TEST_CASE("Explicit modifier", "[Stage]") {

REQUIRE(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
REQUIRE(apply_input(stage, "+D") ==
"-ShiftLeft +ShiftLeft +G -G -ShiftLeft +H -H +ShiftLeft +G -G -ShiftLeft +H -H");
"+G -G -ShiftLeft +H -H +ShiftLeft +G -G -ShiftLeft +H -H");
REQUIRE(apply_input(stage, "-D") == "");
REQUIRE(apply_input(stage, "+D") ==
"+ShiftLeft +G -G -ShiftLeft +H -H +ShiftLeft +G -G -ShiftLeft +H -H");
Expand Down Expand Up @@ -2719,7 +2718,7 @@ TEST_CASE("String typing", "[Stage]") {
REQUIRE(stage.is_clear());

CHECK(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
CHECK(apply_input(stage, "+C") == "-ShiftLeft +ShiftLeft +G -G -ShiftLeft +H -H");
CHECK(apply_input(stage, "+C") == "+G -G -ShiftLeft +H -H");
CHECK(apply_input(stage, "-C") == "");
CHECK(apply_input(stage, "+C") == "+ShiftLeft +G -G -ShiftLeft +H -H");
CHECK(apply_input(stage, "-C") == "");
Expand All @@ -2728,7 +2727,7 @@ TEST_CASE("String typing", "[Stage]") {

CHECK(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
CHECK(apply_input(stage, "+D") ==
"-ShiftLeft +ShiftLeft +G -G -ShiftLeft +H -H +ShiftLeft +G -G -ShiftLeft +H -H");
"+G -G -ShiftLeft +H -H +ShiftLeft +G -G -ShiftLeft +H -H");
CHECK(apply_input(stage, "-D") == "");
CHECK(apply_input(stage, "+D") ==
"+ShiftLeft +G -G -ShiftLeft +H -H +ShiftLeft +G -G -ShiftLeft +H -H");
Expand Down Expand Up @@ -2774,7 +2773,7 @@ TEST_CASE("String typing key repeat", "[Stage]") {

CHECK(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
CHECK(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
CHECK(apply_input(stage, "+A") == "-ShiftLeft +ShiftLeft +X -X -ShiftLeft");
CHECK(apply_input(stage, "+A") == "+X -X -ShiftLeft");
CHECK(apply_input(stage, "+A") == "+ShiftLeft +X -X -ShiftLeft");
CHECK(apply_input(stage, "-A") == "");
CHECK(apply_input(stage, "+C") == "+ShiftLeft +C");
Expand All @@ -2785,7 +2784,7 @@ TEST_CASE("String typing key repeat", "[Stage]") {

CHECK(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
CHECK(apply_input(stage, "+ShiftLeft") == "+ShiftLeft");
CHECK(apply_input(stage, "+B") == "-ShiftLeft +ShiftLeft +W -W -ShiftLeft");
CHECK(apply_input(stage, "+B") == "+W -W -ShiftLeft");
CHECK(apply_input(stage, "+B") == "+ShiftLeft +W -W -ShiftLeft");
CHECK(apply_input(stage, "-B") == "");
CHECK(apply_input(stage, "+C") == "+ShiftLeft +C");
Expand Down

0 comments on commit 6ccfb55

Please sign in to comment.