Skip to content

Commit

Permalink
Autocorrection: handle layer and shifted codes.
Browse files Browse the repository at this point in the history
This commit extends autocorrection's handling for advanced keycodes:

* KC_LSFT, KC_RSFT, and one-shot shifts are ignored.
* Layer switch keys are ignored.
* Shifted keycodes are handled, e.g. symbols like KC_EXLM = S(KC_1).
  • Loading branch information
getreuer committed Feb 21, 2022
1 parent cdc3cac commit e18e15e
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions features/autocorrection.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,34 @@ bool process_autocorrection(uint16_t keycode, keyrecord_t* record) {
}

switch (keycode) {
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
// Ignore shifts, one-shot mods, and layer switch keys.
case KC_LSFT:
case KC_RSFT:
case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
case QK_TO ... QK_TO_MAX:
case QK_MOMENTARY ... QK_MOMENTARY_MAX:
case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:
case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
return true; // Ignore these keys.

#ifndef NO_ACTION_TAPPING
case QK_MOD_TAP ... QK_MOD_TAP_MAX: // Tap-hold keys.
#ifndef NO_ACTION_LAYER
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
// Earlier return if this has not been considered tapped yet.
#endif // NO_ACTION_LAYER
// Ignore when tap-hold keys are held.
if (record->tap.count == 0) { return true; }
// Get the base tapping keycode of a mod- or layer-tap key.
keycode &= 0xff;
// Otherwise when tapped, get the base keycode.
// Fallthrough intended.
#endif // NO_ACTION_TAPPING

// Handle shifted keys, e.g. symbols like KC_EXLM = S(KC_1).
case QK_LSFT ... QK_LSFT + 255:
case QK_RSFT ... QK_RSFT + 255:
keycode &= 0xff; // Get the base keycode.
}

if (!(KC_A <= keycode && keycode <= KC_Z)) {
Expand Down

0 comments on commit e18e15e

Please sign in to comment.