@@ -104,11 +104,16 @@ bool AutoShift::isExplicitlyMapped(Key key) {
104
104
for (uint8_t i{0 }; i < explicitmappings_count_; ++i) {
105
105
LongPress mappedKey = cloneFromProgmem (explicitmappings_[i]);
106
106
if (mappedKey.key == key) {
107
+ // cache the mapped key to not have to search it again
108
+ mapped_key_.key = mappedKey.key ;
109
+ mapped_key_.alternate_key = mappedKey.alternate_key ;
107
110
return true ;
108
111
}
109
112
}
110
113
111
- // If no matches were found, return false
114
+ // If no matches were found, clear mapped_key_ and return false
115
+ mapped_key_.key = Key_Transparent;
116
+ mapped_key_.alternate_key = Key_Transparent;
112
117
return false ;
113
118
}
114
119
@@ -209,17 +214,10 @@ void AutoShift::flushEvent(bool is_long_press) {
209
214
event.key = Runtime.lookupKey (event.addr );
210
215
211
216
// If we have an explicit mapping for that key, apply that.
212
- bool mapped= false ;
213
- for (uint8_t i{0 }; i < explicitmappings_count_; ++i) {
214
- LongPress mappedKey = cloneFromProgmem (explicitmappings_[i]);
215
- if (mappedKey.key == event.key ) {
216
- event.key = mappedKey.alternate_key ;
217
- mapped= true ;
218
- }
219
- }
220
-
221
- // If there was no explicit mapping, just add the shift modifier
222
- if (!mapped) {
217
+ if (mapped_key_.key != Key_Transparent) {
218
+ event.key = mapped_key_.alternate_key ;
219
+ } else {
220
+ // If there was no explicit mapping, just add the shift modifier
223
221
// event.key = longpresses[event.key]
224
222
uint8_t flags = event.key .getFlags ();
225
223
flags ^= SHIFT_HELD;
0 commit comments