diff options
| author | Jules Aguillon | 2025-08-25 01:40:21 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2025-12-28 18:08:36 +0100 |
| commit | 2b60f94ead0f7ac6c1df0b8c60a8c2facd385167 (patch) | |
| tree | 7c7f593000b497dd050a89402b29014d9b8330ab | |
| parent | f082fcdebc4f129cd262ee4a0a6b83d91fde72bb (diff) | |
| download | unexpected-keyboard-2b60f94ead0f7ac6c1df0b8c60a8c2facd385167.tar.gz unexpected-keyboard-2b60f94ead0f7ac6c1df0b8c60a8c2facd385167.zip | |
Enter the suggestion when it's pressed
The current word is replaced by the pressed suggestion.
| -rw-r--r-- | srcs/juloo.keyboard2/CurrentlyTypedWord.java | 10 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyEventHandler.java | 15 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/Suggestions.java | 13 |
3 files changed, 31 insertions, 7 deletions
diff --git a/srcs/juloo.keyboard2/CurrentlyTypedWord.java b/srcs/juloo.keyboard2/CurrentlyTypedWord.java index eba0bb0..15ffd6c 100644 --- a/srcs/juloo.keyboard2/CurrentlyTypedWord.java +++ b/srcs/juloo.keyboard2/CurrentlyTypedWord.java @@ -19,13 +19,16 @@ public final class CurrentlyTypedWord the editor. */ int _cursor; - int refresh_count = 0; - public CurrentlyTypedWord(Callback cb) { _callback = cb; } + public String get() + { + return _w.toString(); + } + public void started(Config conf, InputConnection ic) { _ic = ic; @@ -56,7 +59,7 @@ public final class CurrentlyTypedWord private void callback() { - _callback.currently_typed_word(_w.toString() + refresh_count); + _callback.currently_typed_word(_w.toString()); } /** Estimate the currently typed word after [chars] has been typed. */ @@ -87,7 +90,6 @@ public final class CurrentlyTypedWord _enabled = true; if (has_selection) return; - refresh_count++; type_chars(text_before_cursor.toString()); callback(); } diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 336398c..c6b1730 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -121,7 +121,7 @@ public final class KeyEventHandler @Override public void suggestion_entered(String text) { - // TODO + replace_text_before_cursor(_typedword.get().length(), text + " "); } @Override @@ -235,6 +235,19 @@ public final class KeyEventHandler _typedword.typed(text); } + void replace_text_before_cursor(int remove_length, String new_text) + { + InputConnection conn = _recv.getCurrentInputConnection(); + if (conn == null) + return; + conn.beginBatchEdit(); + conn.deleteSurroundingText(remove_length, 0); + conn.commitText(new_text, 1); + conn.endBatchEdit(); + _autocap.typed(new_text); + _typedword.typed(new_text); + } + /** See {!InputConnection.performContextMenuAction}. */ void send_context_menu_action(int id) { diff --git a/srcs/juloo.keyboard2/Suggestions.java b/srcs/juloo.keyboard2/Suggestions.java index 2009d9a..4c0c97a 100644 --- a/srcs/juloo.keyboard2/Suggestions.java +++ b/srcs/juloo.keyboard2/Suggestions.java @@ -16,10 +16,19 @@ public final class Suggestions public void currently_typed_word(String word) { - // TODO - _callback.set_suggestions(Arrays.asList(word)); + if (word.equals("")) + { + _callback.set_suggestions(NO_SUGGESTIONS); + } + else + { + // TODO + _callback.set_suggestions(Arrays.asList(word)); + } } + static final List<String> NO_SUGGESTIONS = Arrays.asList(); + public static interface Callback { public void set_suggestions(List<String> suggestions); |
