summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
authorPablo Martínez <58857054+elpekenin@users.noreply.github.com>2023-06-04 03:11:54 +0200
committerGitHub <noreply@github.com>2023-06-04 02:11:54 +0100
commitedaf6654143fdd2dffaaa9c3ba8db1c9b282b5d0 (patch)
tree7175ab0777415094c51c11c8fc0c0b4d403eea3b /quantum
parent220dad26d053ef6ecf69653e0a5eb123115a778f (diff)
[Enhancement] Decouple autocorrect logic (#21116)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/process_keycode/process_autocorrect.c19
-rw-r--r--quantum/process_keycode/process_autocorrect.h1
2 files changed, 19 insertions, 1 deletions
diff --git a/quantum/process_keycode/process_autocorrect.c b/quantum/process_keycode/process_autocorrect.c
index 1376788266..7c9cb814e5 100644
--- a/quantum/process_keycode/process_autocorrect.c
+++ b/quantum/process_keycode/process_autocorrect.c
@@ -57,7 +57,7 @@ void autocorrect_toggle(void) {
}
/**
- * @brief handler for determining if autocorrect should process keypress
+ * @brief handler for user to override whether autocorrect should process this keypress
*
* @param keycode Keycode registered by matrix press, per keymap
* @param record keyrecord_t structure
@@ -67,6 +67,23 @@ void autocorrect_toggle(void) {
* @return false Stop processing and escape from autocorrect.
*/
__attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) {
+ return process_autocorrect_default_handler(keycode, record, typo_buffer_size, mods);
+}
+
+/**
+ * @brief fallback handler for determining if autocorrect should process this keypress
+ * can be used by user callback to get the basic keycode being "wrapped"
+ *
+ * NOTE: These values may have been edited by user callback before getting here
+ *
+ * @param keycode Keycode registered by matrix press, per keymap
+ * @param record keyrecord_t structure
+ * @param typo_buffer_size passed along to allow resetting of autocorrect buffer
+ * @param mods allow processing of mod status
+ * @return true Allow autocorection
+ * @return false Stop processing and escape from autocorrect.
+ */
+bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) {
// See quantum_keycodes.h for reference on these matched ranges.
switch (*keycode) {
// Exclude these keycodes from processing.
diff --git a/quantum/process_keycode/process_autocorrect.h b/quantum/process_keycode/process_autocorrect.h
index c7596107e5..00dacbf958 100644
--- a/quantum/process_keycode/process_autocorrect.h
+++ b/quantum/process_keycode/process_autocorrect.h
@@ -9,6 +9,7 @@
bool process_autocorrect(uint16_t keycode, keyrecord_t *record);
bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods);
+bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods);
bool apply_autocorrect(uint8_t backspaces, const char *str);
bool autocorrect_is_enabled(void);