From 445d50a931da95279391f6391b257accec83b58a Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Fri, 15 Mar 2019 15:40:32 -0500 Subject: [PATCH] Fix OneShot premature timeout OneShot keys were failing to activate on the first press because of how the timeout was implemented. Most of the time, at the end of a cycle, `should_cancel_` was being set to `true` because the current time was being compared to the last time a OneShot key was activated, regardless of whether or not a OneShot key was active. As a result, OneShot keys that were pressed for the first time in a while would fail to register as OneShots. This change prevents checking the timeout unless there is an active OneShot key. Fixes #603. Signed-off-by: Michael Richters --- src/kaleidoscope/plugin/OneShot.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/kaleidoscope/plugin/OneShot.cpp b/src/kaleidoscope/plugin/OneShot.cpp index 26a7d788..a571de23 100644 --- a/src/kaleidoscope/plugin/OneShot.cpp +++ b/src/kaleidoscope/plugin/OneShot.cpp @@ -173,7 +173,14 @@ EventHandlerResult OneShot::beforeReportingState() { } EventHandlerResult OneShot::afterEachCycle() { - if (hasTimedOut()) + bool oneshot_active = false; + for (uint8_t i = 0; i < ONESHOT_KEY_COUNT; i++) { + if (state_[i].active) { + oneshot_active = true; + break; + } + } + if (oneshot_active && hasTimedOut()) cancel(); bool is_cancelled = false;