From df3594bd53c71d06f6e103f6782bb26b970beac4 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 19 Feb 2026 00:37:42 +0100 Subject: Autocomplete on space bar and undo on delete (#1179) * Refactor: Implement the space key as an editing action The space key is no longer a CHAR key but now an EDITING key. This allows changing the behavior of the space bar while allowing custom layout users to define a key outputing a space as before. KeyModifier and ComposeKey are updated to treat the space key as before. * Enter the best suggestion when the space bar is pressed * Refactor: Implement backspace as an editing action * Undo suggestion when delete is pressed The delete key (backspace internally) undoes the suggestion if the last action done was entering the suggestion with either the space bar or the candidates view. * Add an option to enable space bar autocomplete This option is off by default. Undoing a completion with backspace works in any case. * Refactor: Track selection emptyness in CurrentlyTypedWord This removes an expensive RPC call. --- srcs/juloo.keyboard2/suggestions/Suggestions.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'srcs/juloo.keyboard2/suggestions/Suggestions.java') diff --git a/srcs/juloo.keyboard2/suggestions/Suggestions.java b/srcs/juloo.keyboard2/suggestions/Suggestions.java index 998d40d..89ed86e 100644 --- a/srcs/juloo.keyboard2/suggestions/Suggestions.java +++ b/srcs/juloo.keyboard2/suggestions/Suggestions.java @@ -13,6 +13,10 @@ public final class Suggestions Callback _callback; Config _config; + /** The suggestion displayed at the center of the candidates view and entered + by the space bar. */ + public String best_suggestion = null; + public Suggestions(Callback c, Config conf) { _callback = c; @@ -24,7 +28,7 @@ public final class Suggestions Cdict dict = _config.current_dictionary; if (word.length() < 2 || dict == null) { - _callback.set_suggestions(NO_SUGGESTIONS); + set_suggestions(NO_SUGGESTIONS); } else { @@ -42,10 +46,16 @@ public final class Suggestions if (dist.length > j && i < 3) suggestions[i++] = dict.word(dist[j]); } - _callback.set_suggestions(Arrays.asList(suggestions)); + set_suggestions(Arrays.asList(suggestions)); } } + void set_suggestions(List ws) + { + _callback.set_suggestions(ws); + best_suggestion = (ws.size() > 0) ? ws.get(0) : null; + } + static final List NO_SUGGESTIONS = Arrays.asList(); public static interface Callback -- cgit v1.2.3