diff --git a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.cpp b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.cpp index 67c6b2c044..589a34baf8 100644 --- a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.cpp +++ b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.cpp @@ -104,11 +104,16 @@ bool AutoShift::isExplicitlyMapped(Key key) { for (uint8_t i{0}; i < explicitmappings_count_; ++i) { LongPress mappedKey = cloneFromProgmem(explicitmappings_[i]); if (mappedKey.key == key) { + // cache the mapped key to not have to search it again + mapped_key_.key = mappedKey.key; + mapped_key_.alternate_key = mappedKey.alternate_key; return true; } } - // If no matches were found, return false + // If no matches were found, clear mapped_key_ and return false + mapped_key_.key = Key_Transparent; + mapped_key_.alternate_key = Key_Transparent; return false; } @@ -209,17 +214,10 @@ void AutoShift::flushEvent(bool is_long_press) { event.key = Runtime.lookupKey(event.addr); // If we have an explicit mapping for that key, apply that. - bool mapped= false; - for (uint8_t i{0}; i < explicitmappings_count_; ++i) { - LongPress mappedKey = cloneFromProgmem(explicitmappings_[i]); - if (mappedKey.key == event.key) { - event.key = mappedKey.alternate_key; - mapped= true; - } - } - - // If there was no explicit mapping, just add the shift modifier - if (!mapped) { + if (mapped_key_.key != Key_Transparent) { + event.key = mapped_key_.alternate_key; + } else { + // If there was no explicit mapping, just add the shift modifier // event.key = longpresses[event.key] uint8_t flags = event.key.getFlags(); flags ^= SHIFT_HELD; diff --git a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h index 1b4e53fde1..8f3aade63a 100644 --- a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h +++ b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h @@ -296,6 +296,10 @@ class AutoShift : public Plugin { // An array of LongPress objects in PROGMEM. LongPress const *explicitmappings_{nullptr}; uint8_t explicitmappings_count_{0}; + + // A cache of the current explicit config key values, so we + // don't have to keep looking them up from PROGMEM. + LongPress mapped_key_ = { .key = Key_Transparent, .alternate_key = Key_Transparent }; }; // =============================================================================