diff --git a/features/select_word.c b/features/select_word.c index 6026045..0a7684a 100644 --- a/features/select_word.c +++ b/features/select_word.c @@ -1,4 +1,4 @@ -// Copyright 2021-2022 Google LLC +// Copyright 2021-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,32 +38,40 @@ bool process_select_word(uint16_t keycode, keyrecord_t* record, if (keycode == sel_keycode && record->event.pressed) { // On key press. const uint8_t mods = get_mods(); #ifndef NO_ACTION_ONESHOT - const uint8_t all_mods = mods | get_oneshot_mods(); + const bool shifted = (mods | get_oneshot_mods()) & MOD_MASK_SHIFT; + clear_oneshot_mods(); #else - const uint8_t all_mods = mods; + const bool shifted = mods & MOD_MASK_SHIFT; #endif // NO_ACTION_ONESHOT - if ((all_mods & MOD_MASK_SHIFT) == 0) { // Select word. + + if (!shifted) { // Select word. #ifdef MAC_HOTKEYS - register_code(KC_LALT); + set_mods(MOD_BIT(KC_LALT)); #else - register_code(KC_LCTL); + set_mods(MOD_BIT(KC_LCTL)); #endif // MAC_HOTKEYS if (state == STATE_NONE) { - SEND_STRING(SS_TAP(X_RGHT) SS_TAP(X_LEFT)); + send_keyboard_report(); + tap_code(KC_RGHT); + tap_code(KC_LEFT); } - register_code(KC_LSFT); + register_mods(MOD_BIT(KC_LSFT)); register_code(KC_RGHT); state = STATE_WORD; } else { // Select line. if (state == STATE_NONE) { - clear_mods(); -#ifndef NO_ACTION_ONESHOT - clear_oneshot_mods(); -#endif // NO_ACTION_ONESHOT #ifdef MAC_HOTKEYS - SEND_STRING(SS_LCTL("a" SS_LSFT("e"))); + set_mods(MOD_BIT(KC_LGUI)); + send_keyboard_report(); + tap_code(KC_LEFT); + register_mods(MOD_BIT(KC_LSFT)); + tap_code(KC_RGHT); #else - SEND_STRING(SS_TAP(X_HOME) SS_LSFT(SS_TAP(X_END))); + clear_mods(); + send_keyboard_report(); + tap_code(KC_HOME); + register_mods(MOD_BIT(KC_LSFT)); + tap_code(KC_END); #endif // MAC_HOTKEYS set_mods(mods); state = STATE_FIRST_LINE; @@ -79,11 +87,10 @@ bool process_select_word(uint16_t keycode, keyrecord_t* record, switch (state) { case STATE_WORD: unregister_code(KC_RGHT); - unregister_code(KC_LSFT); #ifdef MAC_HOTKEYS - unregister_code(KC_LALT); + unregister_mods(MOD_BIT(KC_LSFT) | MOD_BIT(KC_LALT)); #else - unregister_code(KC_LCTL); + unregister_mods(MOD_BIT(KC_LSFT) | MOD_BIT(KC_LCTL)); #endif // MAC_HOTKEYS state = STATE_SELECTED; break; @@ -103,7 +110,7 @@ bool process_select_word(uint16_t keycode, keyrecord_t* record, state = STATE_NONE; return false; } - // Fallthrough. + // Fallthrough intended. default: state = STATE_NONE; }