Skip to content

Commit

Permalink
rewrite sentence case
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelromao committed Jul 26, 2023
1 parent 8dad668 commit 660f6b3
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
____RAISE_L4_____ , XXXXXXX , XXXXXXX , ____RAISE_R4_____),
// |___________________________________________________________________________________________________|

[_SEN_CASE] = LAYOUT_wrapper(
// |___________________________________________________________________________________________________|
___________________SEN_CASE____L1____ , XXXXXXX , XXXXXXX , _________SEN_CASE____R1______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
___________________SEN_CASE____L2______________ , ___________________SEN_CASE____R2______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
XXXXXXX , _________SEN_CASE____L3______________ , ___________________SEN_CASE____R3____ , XXXXXXX ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
__SEN_CASE____L4_ , XXXXXXX , XXXXXXX , __SEN_CASE____R4_),
// |___________________________________________________________________________________________________|

[_FIXED_NAV] = LAYOUT_wrapper(
// |___________________________________________________________________________________________________|
___________________NAVIGATION_L1_____ , XXXXXXX , XXXXXXX , _________NAVIGATION_R1_______________ ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
____RAISE_L4_____ , ____RAISE_R4_____),
// |___________________________________________________________________________________________________|

[_SEN_CASE] = LAYOUT_wrapper(
// |___________________________________________________________________________________________________|
___________________SEN_CASE____L1____ , _________SEN_CASE____R1______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
___________________SEN_CASE____L2______________ , ___________________SEN_CASE____R2______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_________SEN_CASE____L3______________ , ___________________SEN_CASE____R3____ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
__SEN_CASE____L4_ , __SEN_CASE____R4_),
// |___________________________________________________________________________________________________|

[_FIXED_NAV] = LAYOUT_wrapper(
// |___________________________________________________________________________________________________|
___________________NAVIGATION_L1_____ , _________NAVIGATION_R1_______________ ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
____RAISE_L4_____ , ____RAISE_R4_____),
// |___________________________________________________________________________________________________|

[_SEN_CASE] = LAYOUT_wrapper(
// |___________________________________________________________________________________________________|
___________________SEN_CASE____L1____ , _________SEN_CASE____R1______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
___________________SEN_CASE____L2______________ , ___________________SEN_CASE____R2______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_________SEN_CASE____L3______________ , ___________________SEN_CASE____R3____ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
__SEN_CASE____L4_ , __SEN_CASE____R4_),
// |___________________________________________________________________________________________________|

[_FIXED_NAV] = LAYOUT_wrapper(
// |___________________________________________________________________________________________________|
___________________NAVIGATION_L1_____ , _________NAVIGATION_R1_______________ ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
XXXXXXX , XXXXXXX , XXXXXXX , ____RAISE_L4_____ , XXXXXXX , ____RAISE_R4_____ , XXXXXXX , XXXXXXX , XXXXXXX),
// |_______________________________________________________________________________________________________________________|

[_SEN_CASE] = LAYOUT_wrapper(
// |_______________________________________________________________________________________________________________________|
___________________SEN_CASE____L1____ , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , _________SEN_CASE____R1______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
___________________SEN_CASE____L2______________ , XXXXXXX , XXXXXXX , ___________________SEN_CASE____R2______________ ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
XXXXXXX , _________SEN_CASE____L3______________ , XXXXXXX , XXXXXXX , ___________________SEN_CASE____R3____ , XXXXXXX ,
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
XXXXXXX , XXXXXXX , XXXXXXX , __SEN_CASE____L4_ , XXXXXXX , __SEN_CASE____R4_ , XXXXXXX , XXXXXXX , XXXXXXX),
// |_______________________________________________________________________________________________________________________|

[_FIXED_NAV] = LAYOUT_wrapper(
// |_______________________________________________________________________________________________________________________|
___________________NAVIGATION_L1_____ , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , _________NAVIGATION_R1_______________ ,
Expand Down
1 change: 0 additions & 1 deletion src/qmk/users/rafaelromao/definitions/keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ enum {
#define RAI_TAC LT(_RAISE, TG_ACNT)
#define RAI_SPC LT(_RAISE, KC_SPC)
#define RAI_ACT OSL(_ACCENT) // Hold behavior is implemented in intercepted code
#define MED_OSF LT(_MEDIA, OS_LSFT) // Hold and tap behaviors are implemented in intercepted code

#define MAC_KCD LT(_MACROS, KC_D)
#define MAC_KCI LT(_MACROS, KC_I)
Expand Down
10 changes: 0 additions & 10 deletions src/qmk/users/rafaelromao/definitions/keymap_blocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@
#define ___________________RAISE_R3__________ TD_TILD , TD_SLSH , KC_ASTR , TD_NOT
#define ____RAISE_R4_____ _______ , _______

#define ___________________SEN_CASE____L1____ _______ , _______ , _______ , _______
#define ___________________SEN_CASE____L2______________ _______ , _______ , _______ , _______ , _______
#define _________SEN_CASE____L3______________ _______ , _______ , _______ , _______
#define __SEN_CASE____L4_ NAV_CAN , LOW_NSE

#define _________SEN_CASE____R1______________ _______ , _______ , _______ , _______
#define ___________________SEN_CASE____R2______________ _______ , _______ , _______ , _______ , _______
#define ___________________SEN_CASE____R3____ _______ , _______ , _______ , _______
#define __SEN_CASE____R4_ _______ , MED_OSF

#define ___________________MEDIA_L1__________ _______ , MC_ESC , MC_SAVE , HYPR_G
#define ___________________MEDIA_L2____________________ HYPR_D , KC_LSFT , KC_LCTL , KC_LGUI , HYPR_W
#define _________MEDIA_L3____________________ KC_RALT , HYPR_C , KC_LALT , HYPR_V
Expand Down
93 changes: 44 additions & 49 deletions src/qmk/users/rafaelromao/features/sentence_case.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,58 @@

#include "sentence_case.h"

process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *record) {
bool isOneShotLockedShift = get_oneshot_locked_mods() & MOD_MASK_SHIFT;
bool isOneShotShift = isOneShotLockedShift || get_oneshot_mods() & MOD_MASK_SHIFT;
sentence_case_t sentence_case = {.state = SENTENCE_CASE_NONE};

switch (keycode) {
case NAV_CAN:
if (record->tap.count == 0) {
if (record->event.pressed) {
disable_oneshot_layer();
layer_on(_NAVIGATION);
} else {
layer_off(_NAVIGATION);
}
} else {
if (record->event.pressed) {
disable_smart_case();
clear_shift();
}
}
return PROCESS_RECORD_RETURN_FALSE;
void start_sentence_case(void) {
// Called after . ? and !
sentence_case.state = SENTENCE_CASE_STARTED;
}

case LOW_NSE:
if (record->tap.count == 0) {
if (record->event.pressed) {
disable_oneshot_layer();
layer_on(_LOWER);
} else {
layer_off(_LOWER);
process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
// Navigation
case KC_HOME:
case KC_END:
case KC_LEFT:
case KC_RIGHT:
if (sentence_case.state == SENTENCE_CASE_STARTED) {
clear_shift();
sentence_case.state = SENTENCE_CASE_NONE;
return PROCESS_RECORD_CONTINUE;
}
} else {
if (record->event.pressed) {
}
}
if (record->tap.count && record->event.pressed) {
uint16_t key = extract_base_tapping_keycode(keycode);
switch (key) {
// Space
case KC_SPC:
if (sentence_case.state == SENTENCE_CASE_STARTED) {
tap_code(KC_SPC);
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
add_oneshot_mods(MOD_LSFT);
sentence_case.state = SENTENCE_CASE_STARTED;
return PROCESS_RECORD_RETURN_FALSE;
}
}
return PROCESS_RECORD_RETURN_FALSE;

case MED_OSF:
if (record->tap.count == 0) {
if (record->event.pressed) {
layer_on(_MEDIA);
} else {
layer_off(_MEDIA);
}
switch (keycode) {
// Cancel
case NAV_REP:
case QK_REP:
if (sentence_case.state == SENTENCE_CASE_STARTED) {
clear_shift();
sentence_case.state = SENTENCE_CASE_NONE;
return PROCESS_RECORD_RETURN_FALSE;
}
} else {
if (record->event.pressed) {
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
if (!isOneShotShift) {
add_oneshot_mods(MOD_LSFT);
}
// One Shot Shift
case MED_CAS:
if (sentence_case.state == SENTENCE_CASE_STARTED) {
add_oneshot_mods(MOD_LSFT);
return PROCESS_RECORD_RETURN_FALSE;
}
}
return PROCESS_RECORD_RETURN_FALSE;
default:
sentence_case.state = SENTENCE_CASE_NONE;
}
}

return PROCESS_RECORD_CONTINUE;
}
7 changes: 7 additions & 0 deletions src/qmk/users/rafaelromao/features/sentence_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
#include "../definitions/process_record.h"
#include "custom_oneshot.h"

typedef enum { SENTENCE_CASE_NONE, SENTENCE_CASE_STARTED } sentence_case_state_t;

typedef struct {
sentence_case_state_t state;
} sentence_case_t;

void start_sentence_case(void);
process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *record);
18 changes: 6 additions & 12 deletions src/qmk/users/rafaelromao/features/tapdance.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ void td_ques(tap_dance_state_t *state, void *user_data) {
case TD_SINGLE_TAP:
tap_code16(KC_QUES);
#ifdef LEADER_ENABLE
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
start_sentence_case();
#endif
break;
case TD_DOUBLE_SINGLE_TAP:
Expand All @@ -384,8 +383,7 @@ void td_ques(tap_dance_state_t *state, void *user_data) {
tap_code(KC_END);
tap_code16(KC_QUES);
#ifdef LEADER_ENABLE
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
start_sentence_case();
#endif
break;
default:
Expand Down Expand Up @@ -433,16 +431,14 @@ void td_not(tap_dance_state_t *state, void *user_data) {
case TD_SINGLE_TAP:
tap_code16(KC_EXLM);
#ifdef LEADER_ENABLE
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
start_sentence_case();
#endif
break;
case TD_SINGLE_HOLD:
tap_code(KC_END);
tap_code16(KC_EXLM);
#ifdef LEADER_ENABLE
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
start_sentence_case();
#endif
break;
case TD_DOUBLE_TAP:
Expand Down Expand Up @@ -484,8 +480,7 @@ void td_dot(tap_dance_state_t *state, void *user_data) {
case TD_SINGLE_TAP:
tap_code(KC_DOT);
#ifdef LEADER_ENABLE
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
start_sentence_case();
#endif
break;
case TD_DOUBLE_SINGLE_TAP:
Expand All @@ -502,8 +497,7 @@ void td_dot(tap_dance_state_t *state, void *user_data) {
tap_code16(KC_END);
tap_code(KC_DOT);
#ifdef LEADER_ENABLE
set_oneshot_layer(_SEN_CASE, ONESHOT_START);
reset_oneshot_timer();
start_sentence_case();
#endif
break;
default:
Expand Down
1 change: 1 addition & 0 deletions src/qmk/users/rafaelromao/features/tapdance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "dynamic_macro.h"
#include "macros.h"
#include "accents.h"
#include "sentence_case.h"

typedef enum {
TD_NONE,
Expand Down
12 changes: 6 additions & 6 deletions src/qmk/users/rafaelromao/rafaelromao.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
break;
};

// Process Repeat Key
switch (process_repeat(keycode, record)) {
#ifdef LEADER_ENABLE
// Process Sentence Case
switch (process_sentence_case(keycode, record)) {
case PROCESS_RECORD_RETURN_TRUE:
return true;
case PROCESS_RECORD_RETURN_FALSE:
return false;
default:
break;
};
#endif

#ifdef LEADER_ENABLE
// Process Sentence Case
switch (process_sentence_case(keycode, record)) {
// Process Repeat Key
switch (process_repeat(keycode, record)) {
case PROCESS_RECORD_RETURN_TRUE:
return true;
case PROCESS_RECORD_RETURN_FALSE:
return false;
default:
break;
};
#endif

// Process custom_shift
switch (process_custom_shift(keycode, record)) {
Expand Down

0 comments on commit 660f6b3

Please sign in to comment.