From a1d0342033460a13407deb27cac3ed5ad13ab47f Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 12 Apr 2026 14:33:27 +0200 Subject: 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.--- srcs/juloo.keyboard2/KeyEventHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java') 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; } -- cgit v1.2.3