Compare commits

..

3 Commits

Author SHA1 Message Date
Mark bf6faeb94f
Improved spellcheck sending 2022-07-21 21:20:16 -07:00
Mark c757a1686c
Added keycode type checkers to spellcheck 2022-07-21 20:01:49 -07:00
Mark 7be80e97fd
Fixed a typo 2022-07-21 19:44:13 -07:00
5 changed files with 116 additions and 43 deletions

View File

@ -4,3 +4,13 @@
extern const int8_t fft_array_to_col[4][14];
extern const int8_t fft_col_to_array[10][5];
extern uint8_t layer_layouts[];
// Language keymap ids for layers.
// See layers/definitions/symbols.h.
enum layer_layout_ids {
LAYOUT_NULL, // This layer doesn't care what keymap the OS is using
LAYOUT_EN, // This layer is designed for the standard keymapping
LAYOUT_RU,
};

View File

@ -1,11 +1,71 @@
#ifdef BETA_ENABLE_SPELLCHECK
#include "keymap_russian.h"
#include "keymap_us_international.h"
#include "features/spellcheck.h"
#include "features/beta_rawhid.h"
#include "extra_mappings.h"
uint8_t spellcheck_buffer[SPELLCHECK_BUFFER_MAX] = {0};
uint8_t spellcheck_buffer_size = 0;
// Return one of the following.
#define SPELLCHECK_WORD 2
#define SPELLCHECK_SPACE 1
#define SPELLCHECK_NEITHER 0
uint8_t keycode_type_en(uint8_t mods, uint16_t keycode) {
if (
KC_A <= keycode && keycode <= KC_Z // basic letters
) {
return SPELLCHECK_WORD;
} else if (
( // Include these
(KC_1 <= keycode && keycode <= KC_SLSH) || // Symbols
// Treat " (shifted ') as a word boundary.
((keycode == KC_QUOT) && ((mods & MOD_MASK_SHIFT) != 0))
) && !( // Don't include these
(keycode == KC_ESC) ||
(keycode == KC_ENTER)
)
) {
return SPELLCHECK_SPACE;
} else {
return SPELLCHECK_NEITHER;
}
}
uint8_t keycode_type_ru(uint8_t mods, uint16_t keycode) {
if (
KC_A <= keycode && keycode <= KC_Z // basic letters
) {
return SPELLCHECK_WORD;
} else if (
KC_1 <= keycode && keycode <= KC_0
) {
return SPELLCHECK_SPACE;
}
switch (keycode) {
case RU_YO:
case RU_HA:
case RU_HARD:
case RU_E:
case RU_BE:
case RU_YU:
return SPELLCHECK_WORD;
case RU_MINS:
case RU_EQL:
case RU_DOT:
case RU_BSLS:
return SPELLCHECK_SPACE;
}
return SPELLCHECK_NEITHER;
}
bool process_spellcheck(uint16_t keycode, keyrecord_t* record) {
@ -71,41 +131,52 @@ bool process_spellcheck(uint16_t keycode, keyrecord_t* record) {
return true; // Ignore these keys.
}
if (keycode == KC_QUOT) {
// Treat " (shifted ') as a word boundary.
if ((mods & MOD_MASK_SHIFT) != 0) { keycode = KC_SPC; }
} else if (!(KC_A <= keycode && keycode <= KC_Z)) {
if (keycode == KC_BSPC) {
// Remove last character from the buffer.
if (spellcheck_buffer_size > 0) { --spellcheck_buffer_size; }
if (keycode == KC_BSPC) {
// Remove last character from buffer
if (spellcheck_buffer_size > 0) { --spellcheck_buffer_size; }
return true;
}
uint8_t keycode_type;
switch (layer_layouts[biton32(layer_state)]) {
case LAYOUT_EN:
keycode_type = keycode_type_en(mods, keycode);
break;
case LAYOUT_RU:
keycode_type = keycode_type_ru(mods, keycode);
break;
default:
keycode_type = SPELLCHECK_NEITHER;
break;
}
switch(keycode_type) {
// No modifications are needed if this is a regular word character
case SPELLCHECK_WORD:
// If the buffer is full, rotate it to discard the oldest character.
if (spellcheck_buffer_size >= SPELLCHECK_BUFFER_MAX) {
memmove(spellcheck_buffer, spellcheck_buffer + 1, SPELLCHECK_BUFFER_MAX - 1);
spellcheck_buffer_size = SPELLCHECK_BUFFER_MAX - 1;
}
spellcheck_buffer[spellcheck_buffer_size++] = (uint8_t) keycode;
return true;
} else if (KC_1 <= keycode && keycode <= KC_SLSH && keycode != KC_ESC) {
// Set a word boundary if space, period, digit, etc. is pressed.
// Behave more conservatively for the enter key. Reset, so that enter
// can't be used on a word ending.
if (keycode == KC_ENT) { spellcheck_buffer_size = 0; }
keycode = KC_SPC;
} else {
// Clear state if some other non-alpha key is pressed.
case SPELLCHECK_SPACE:
// If this is a word break, send word and reset buffer
if (spellcheck_buffer_size > 0) {
hid_send_word();
spellcheck_buffer_size = 0;
}
return true;
case SPELLCHECK_NEITHER:
spellcheck_buffer_size = 0;
return true;
}
}
// If the buffer is full, rotate it to discard the oldest character.
if (spellcheck_buffer_size >= SPELLCHECK_BUFFER_MAX) {
memmove(spellcheck_buffer, spellcheck_buffer + 1, SPELLCHECK_BUFFER_MAX - 1);
spellcheck_buffer_size = SPELLCHECK_BUFFER_MAX - 1;
}
// NOTE: `keycode` must be a basic keycode (0-255) by this point.
// A to Z keycodes
if (keycode >= 0x04 && keycode <= 0x1D) {
spellcheck_buffer[spellcheck_buffer_size++] = (uint8_t) keycode;
} else if (spellcheck_buffer_size > 0) {
hid_send_word();
spellcheck_buffer_size = 0;
}
return true;

View File

@ -22,14 +22,6 @@ extern rgb_config_t rgb_matrix_config;
#define LC_RU_G LC_HSV(153, 255, 153)
#define LC_RU_K LC_HSV( 0, 255, 145)
// Language keymap ids for layers.
// See layers/definitions/symbols.h.
enum layer_layout_ids {
LAYOUT_NULL, // This layer doesn't care what keymap the OS is using
LAYOUT_EN, // This layer is designed for the standard keymapping
LAYOUT_RU,
};
// Define custom keys
// (Must be done before keymaps are loaded)
enum custom_keycodes {

View File

@ -14,7 +14,7 @@
// What OS keyboard layout this layer is designed for.
// See keymap.h for possible values.
// See extra_mappings.h for possible values.
//
// Every layer must have this section.
#ifdef BETA_LAYER_LAYOUTS

View File

@ -1,5 +1,5 @@
#include "layers.h"
#include "extra_mappings.h"
// Create keymap array
#define BETA_LAYER_KEYS
@ -49,7 +49,7 @@ void set_layer_color(int layer) {
void set_layer_matrix_indicator(void) {
void rgb_matrix_indicators_user(void) {
if (keyboard_config.disable_layer_led) {
return;
}