Skip to content

Commit

Permalink
Fixed keyrepeat might match
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Jan 20, 2021
1 parent c8adf82 commit 725d563
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/runtime/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ KeySequence Stage::apply_input(const KeyEvent event) {
if (event.state == KeyState::Down) {
// merge key repeats
auto it = find_key(m_sequence, event.key);
if (it != end(m_sequence))
if (it->state == KeyState::DownMatched)
if (it != end(m_sequence)) {
const auto is_repeat = !std::count(m_sequence.begin(), m_sequence.end(),
KeyEvent{ event.key, KeyState::Up });
if (is_repeat)
m_sequence.erase(it);
}
}
m_sequence.push_back(event);

Expand Down
9 changes: 9 additions & 0 deletions src/test/test1_ParseConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ TEST_CASE("Problems", "[ParseConfig]") {
C >> CommandA
)";
REQUIRE_THROWS(parse_config(string));

// no default mapping (which is ok)
string = R"(
C >> CommandA
[window class='']
CommandA >> D
)";
REQUIRE_NOTHROW(parse_config(string));
}

//--------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions src/test/test3_Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,19 @@ TEST_CASE("Might match, then no match or match", "[Stage]") {
REQUIRE(apply_input(stage, "+B") == "+2");
REQUIRE(apply_input(stage, "-B") == "-2");
}
//--------------------------------------------------------------------

TEST_CASE("Keyrepeat might match", "[Stage]") {
auto config = R"(
Meta{C} >> Control{C}
)";
Stage stage = create_stage(config);

REQUIRE(apply_input(stage, "+MetaLeft") == "");
REQUIRE(apply_input(stage, "+MetaLeft") == "");
REQUIRE(apply_input(stage, "+C") == "+ControlLeft +C");
REQUIRE(apply_input(stage, "-C") == "-ControlLeft -C");
REQUIRE(apply_input(stage, "-MetaLeft") == "");
}

//--------------------------------------------------------------------

0 comments on commit 725d563

Please sign in to comment.