abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyEventHandler.java
diff options
context:
space:
mode:
authorJules Aguillon2025-12-28 19:02:45 +0100
committerGitHub2025-12-28 19:02:45 +0100
commit4d4c22b4e21505000d92fa3b6c1f400379c51cd4 (patch)
tree0d8d7373575c4fc98cb342a4ab73f1192f700f4e /srcs/juloo.keyboard2/KeyEventHandler.java
parentdfaf4dbb5766bf134cbf97d0516493e2256d2e5a (diff)
parentbdb05bcef060ee2aefab7663bb5441ea1398dd95 (diff)
downloadunexpected-keyboard-4d4c22b4e21505000d92fa3b6c1f400379c51cd4.tar.gz
unexpected-keyboard-4d4c22b4e21505000d92fa3b6c1f400379c51cd4.zip
Merge pull request #1150 from Julow/candidates_view
Candidates view
Diffstat (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java')
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java50
1 files changed, 43 insertions, 7 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index fc3a641..17c7d7b 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;
@@ -30,23 +33,29 @@ 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(handler, 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
@@ -111,11 +120,23 @@ public final class KeyEventHandler
}
@Override
+ public void suggestion_entered(String text)
+ {
+ replace_text_before_cursor(_typedword.get().length(), text + " ");
+ }
+
+ @Override
public void paste_from_clipboard_pane(String content)
{
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)
@@ -202,16 +223,31 @@ 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(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);
+ conn.commitText(text, 1);
+ }
+
+ 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();
}
/** See {!InputConnection.performContextMenuAction}. */
@@ -467,7 +503,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);