From 98c1b8db82c0da8f49eb12d18c9001a57009eca5 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 27 Jul 2025 22:09:45 +0200 Subject: Candidates view The `CandidatesView` is implemented as a `LinearLayout` that is divided horizontally with up to 3 `TextView`. It might in the future contain buttons on the sides. The candidate view is nested into the input view rather than using Android's `setCandidatesView` and callbacks as the API is unreliable and complicated. The first suggestion goes in the middle to be more accessible. The second suggestion goes on the right to be more accessible to the right-handed, because it must go somewhere. --- srcs/juloo.keyboard2/KeyEventHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java') diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index fc3a641..145acbe 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -110,6 +110,12 @@ public final class KeyEventHandler update_meta_state(mods); } + @Override + public void suggestion_entered(String text) + { + // TODO + } + @Override public void paste_from_clipboard_pane(String content) { -- cgit v1.2.3 From f082fcdebc4f129cd262ee4a0a6b83d91fde72bb Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 16 Aug 2025 18:48:00 +0200 Subject: 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. --- srcs/juloo.keyboard2/KeyEventHandler.java | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java') 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); -- cgit v1.2.3 From 2b60f94ead0f7ac6c1df0b8c60a8c2facd385167 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 25 Aug 2025 01:40:21 +0200 Subject: Enter the suggestion when it's pressed The current word is replaced by the pressed suggestion. --- srcs/juloo.keyboard2/KeyEventHandler.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java') 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) { -- cgit v1.2.3 From 2208079e489ef7652e28294130825d7451e01571 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 2 Oct 2025 01:59:07 +0200 Subject: CurrentlyTypedWord: Handle key events Currently, refreshing the current word on each key event. Refreshing is done after a short delay, to ensure the editor has handled the event. --- srcs/juloo.keyboard2/KeyEventHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java') diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index c6b1730..057033b 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -33,11 +33,12 @@ public final class KeyEventHandler public KeyEventHandler(IReceiver recv) { _recv = recv; - _autocap = new Autocapitalisation(recv.getHandler(), + Handler handler = recv.getHandler(); + _autocap = new Autocapitalisation(handler, this.new Autocapitalisation_callback()); _mods = Pointers.Modifiers.EMPTY; _suggestions = new Suggestions(recv); - _typedword = new CurrentlyTypedWord(this); + _typedword = new CurrentlyTypedWord(handler, this); } /** Editing just started. */ @@ -222,7 +223,10 @@ public final class KeyEventHandler metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE)); if (eventAction == KeyEvent.ACTION_UP) + { _autocap.event_sent(eventCode, metaState); + _typedword.event_sent(eventCode, metaState); + } } void send_text(String text) -- cgit v1.2.3 From bdb05bcef060ee2aefab7663bb5441ea1398dd95 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 23 Nov 2025 17:54:56 +0100 Subject: Fix CurrentlyTypedWord counting the first letter twice --- srcs/juloo.keyboard2/KeyEventHandler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java') diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 057033b..17c7d7b 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -234,9 +234,9 @@ public final class KeyEventHandler InputConnection conn = _recv.getCurrentInputConnection(); if (conn == null) return; - conn.commitText(text, 1); _autocap.typed(text); _typedword.typed(text); + conn.commitText(text, 1); } void replace_text_before_cursor(int remove_length, String new_text) @@ -248,8 +248,6 @@ public final class KeyEventHandler conn.deleteSurroundingText(remove_length, 0); conn.commitText(new_text, 1); conn.endBatchEdit(); - _autocap.typed(new_text); - _typedword.typed(new_text); } /** See {!InputConnection.performContextMenuAction}. */ -- cgit v1.2.3