diff options
| author | Jules Aguillon | 2025-08-16 18:48:00 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2025-12-28 18:08:12 +0100 |
| commit | f082fcdebc4f129cd262ee4a0a6b83d91fde72bb (patch) | |
| tree | 74dd1045f5e2584c56246b40bd9904a5eb865a8e /srcs/juloo.keyboard2/KeyEventHandler.java | |
| parent | 98c1b8db82c0da8f49eb12d18c9001a57009eca5 (diff) | |
| download | unexpected-keyboard-f082fcdebc4f129cd262ee4a0a6b83d91fde72bb.tar.gz unexpected-keyboard-f082fcdebc4f129cd262ee4a0a6b83d91fde72bb.zip | |
Track the currently typed word
The `CurrentlyTypedWord` class tracks the word that is being typed. It's
implemented on the same model as Autocapitalisation and avoid expensive
IPC calls when possible.
The `Suggestions` class is where the suggestion lookup should go. It
currently just echoes the current word.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyEventHandler.java | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 145acbe..336398c 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -12,10 +12,13 @@ import java.util.Iterator; public final class KeyEventHandler implements Config.IKeyEventHandler, - ClipboardHistoryService.ClipboardPasteCallback + ClipboardHistoryService.ClipboardPasteCallback, + CurrentlyTypedWord.Callback { IReceiver _recv; Autocapitalisation _autocap; + Suggestions _suggestions; + CurrentlyTypedWord _typedword; /** State of the system modifiers. It is updated whether a modifier is down or up and a corresponding key event is sent. */ Pointers.Modifiers _mods; @@ -33,20 +36,25 @@ public final class KeyEventHandler _autocap = new Autocapitalisation(recv.getHandler(), this.new Autocapitalisation_callback()); _mods = Pointers.Modifiers.EMPTY; + _suggestions = new Suggestions(recv); + _typedword = new CurrentlyTypedWord(this); } /** Editing just started. */ public void started(Config conf) { - _autocap.started(conf, _recv.getCurrentInputConnection()); + InputConnection ic = _recv.getCurrentInputConnection(); + _autocap.started(conf, ic); + _typedword.started(conf, ic); _move_cursor_force_fallback = conf.editor_config.should_move_cursor_force_fallback; } /** Selection has been updated. */ - public void selection_updated(int oldSelStart, int newSelStart) + public void selection_updated(int oldSelStart, int newSelStart, int newSelEnd) { _autocap.selection_updated(oldSelStart, newSelStart); + _typedword.selection_updated(oldSelStart, newSelStart, newSelEnd); } /** A key is being pressed. There will not necessarily be a corresponding @@ -122,6 +130,12 @@ public final class KeyEventHandler send_text(content); } + @Override + public void currently_typed_word(String word) + { + _suggestions.currently_typed_word(word); + } + /** Update [_mods] to be consistent with the [mods], sending key events if needed. */ void update_meta_state(Pointers.Modifiers mods) @@ -211,13 +225,14 @@ public final class KeyEventHandler _autocap.event_sent(eventCode, metaState); } - void send_text(CharSequence text) + void send_text(String text) { InputConnection conn = _recv.getCurrentInputConnection(); if (conn == null) return; conn.commitText(text, 1); _autocap.typed(text); + _typedword.typed(text); } /** See {!InputConnection.performContextMenuAction}. */ @@ -473,7 +488,7 @@ public final class KeyEventHandler return (conn.getSelectedText(0) != null); } - public static interface IReceiver + public static interface IReceiver extends Suggestions.Callback { public void handle_event_key(KeyValue.Event ev); public void set_shift_state(boolean state, boolean lock); |
