-
Notifications
You must be signed in to change notification settings - Fork 12
/
select_word.c
77 lines (70 loc) · 2.42 KB
/
select_word.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "select_word.h"
select_word_t select_word = {.state = STATE_NONE};
process_record_result_t process_select_word(uint16_t keycode, keyrecord_t* record) {
bool isMacOS = is_macos();
if ((keycode == MC_SELW || keycode == MC_SELL) && record->event.pressed) {
if (keycode == MC_SELL || select_word.state == STATE_LINE_SELECTED) {
// Select Line
if (select_word.state == STATE_NONE) {
tap_code(KC_HOME);
tap_code(KC_HOME);
register_mods(MOD_LSFT);
wait_ms(30);
tap_code(KC_DOWN);
select_word.state = STATE_FIRST_LINE;
} else {
register_mods(MOD_LSFT);
tap_code(KC_DOWN);
select_word.state = STATE_LINE;
}
} else {
// Select Word
if (isMacOS) {
register_code(KC_LALT);
} else {
register_code(KC_LCTL);
}
if (select_word.state == STATE_NONE) {
tap_code(KC_LEFT);
tap_code(KC_RIGHT);
}
register_mods(MOD_LSFT);
register_code(KC_LEFT);
select_word.state = STATE_WORD;
}
return PROCESS_RECORD_RETURN_FALSE;
}
switch (select_word.state) {
case STATE_WORD:
unregister_code(KC_LEFT);
unregister_mods(MOD_LSFT);
if (isMacOS) {
unregister_code(KC_LALT);
} else {
unregister_code(KC_LCTL);
}
select_word.state = STATE_WORD_SELECTED;
break;
case STATE_FIRST_LINE:
case STATE_LINE:
unregister_mods(MOD_LSFT);
select_word.state = STATE_LINE_SELECTED;
break;
case STATE_WORD_SELECTED:
if (keycode != MC_SELW && record->event.pressed) {
unregister_mods(MOD_LSFT);
tap_code(KC_LEFT);
select_word.state = STATE_NONE;
return PROCESS_RECORD_CONTINUE;
}
case STATE_LINE_SELECTED:
if (keycode != MC_SELW && record->event.pressed) {
unregister_mods(MOD_LSFT);
select_word.state = STATE_NONE;
return PROCESS_RECORD_CONTINUE;
}
default:
select_word.state = STATE_NONE;
}
return PROCESS_RECORD_CONTINUE;
}