diff options
| author | Jules Aguillon | 2026-04-12 14:33:27 +0200 |
|---|---|---|
| committer | GitHub | 2026-04-12 14:33:27 +0200 |
| commit | a1d0342033460a13407deb27cac3ed5ad13ab47f (patch) | |
| tree | 0724c2407f23f94f7803494294ddd24f92f90237 /srcs/juloo.keyboard2/KeyEventHandler.java | |
| parent | 5ec663c306907a32d21c910dc6df69d11b7ab243 (diff) | |
| download | unexpected-keyboard-a1d0342033460a13407deb27cac3ed5ad13ab47f.tar.gz unexpected-keyboard-a1d0342033460a13407deb27cac3ed5ad13ab47f.zip | |
Better spell check with cursor in the middle of a word (#1233)
* Better spell check with cursor in the middle of a word
Suggestions are based on the entire word and no longer the part of the
word just before the cursor. Also, tapping a suggestion or the space bar
autocorrect replaces the entire word.
* Reduce the number of calls to refresh_current_word
While the cursor moves, calls to refresh_current_word are now only done
when the cursor exits the current word.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyEventHandler.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index fd283df..8691cda 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -129,7 +129,8 @@ public final class KeyEventHandler public void suggestion_entered(String text) { String old = _typedword.get(); - replace_text_before_cursor(old.length(), text + " "); + int cur_rel = _typedword.cursor_relative(); + replace_surrounding_text(old.length() + cur_rel, -cur_rel, text + " "); last_replaced_word = old; last_replacement_word_len = text.length() + 1; } @@ -256,13 +257,14 @@ public final class KeyEventHandler clear_space_bar_state(); } - void replace_text_before_cursor(int remove_length, String new_text) + void replace_surrounding_text(int remove_before, int remove_after, + String new_text) { InputConnection conn = _recv.getCurrentInputConnection(); if (conn == null) return; conn.beginBatchEdit(); - conn.deleteSurroundingText(remove_length, 0); + conn.deleteSurroundingText(remove_before, remove_after); conn.commitText(new_text, 1); conn.endBatchEdit(); } @@ -540,7 +542,7 @@ public final class KeyEventHandler { if (last_replaced_word != null) { - replace_text_before_cursor(last_replacement_word_len, + replace_surrounding_text(last_replacement_word_len, 0, last_replaced_word + " "); last_replaced_word = null; } |
