diff options
| author | Jules Aguillon | 2024-02-04 00:27:02 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2024-02-04 00:29:07 +0100 |
| commit | 2c52e94e0bab82fe0300e2753bec0e559668cdd0 (patch) | |
| tree | b57b0dee2ac9be30197d222222c481494da546d2 /srcs/juloo.keyboard2/KeyEventHandler.java | |
| parent | 3adf95a4c99f592f4d36b439d90e928495bc1b7d (diff) | |
| download | unexpected-keyboard-2c52e94e0bab82fe0300e2753bec0e559668cdd0.tar.gz unexpected-keyboard-2c52e94e0bab82fe0300e2753bec0e559668cdd0.zip | |
Workaround cursor slider bug in Acode
Moving the cursor with setSelection has no effect on Acode, for which
the fallback must be used.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyEventHandler.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 9ed6268..51d4385 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -1,6 +1,7 @@ package juloo.keyboard2; import android.os.Looper; +import android.text.InputType; import android.view.KeyEvent; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; @@ -18,7 +19,10 @@ public final class KeyEventHandler implements Config.IKeyEventHandler /** Consistent with [_mods]. This is a mutable state rather than computed from [_mods] to ensure that the meta state is correct while up and down events are sent for the modifier keys. */ - int _meta_state; + int _meta_state = 0; + /** Whether to force sending arrow keys to move the cursor when + [setSelection] could be used instead. */ + boolean _move_cursor_force_fallback = false; public KeyEventHandler(Looper looper, IReceiver recv) { @@ -32,6 +36,12 @@ public final class KeyEventHandler implements Config.IKeyEventHandler public void started(EditorInfo info) { _autocap.started(info, _recv.getCurrentInputConnection()); + // Workaround a bug in Acode, which answers to [getExtractedText] but do + // not react to [setSelection] while returning [true]. + // Note: Using & to workaround a bug in Acode, which sets several + // variations at once. + _move_cursor_force_fallback = (info.inputType & InputType.TYPE_MASK_VARIATION & + InputType.TYPE_TEXT_VARIATION_PASSWORD) != 0; } /** Selection has been updated. */ @@ -232,7 +242,8 @@ public final class KeyEventHandler implements Config.IKeyEventHandler return; ExtractedText et = get_cursor_pos(conn); // Fallback to sending key events - if (et == null + if (_move_cursor_force_fallback + || et == null || _mods.has(KeyValue.Modifier.CTRL) || _mods.has(KeyValue.Modifier.ALT) || _mods.has(KeyValue.Modifier.META)) @@ -256,7 +267,8 @@ public final class KeyEventHandler implements Config.IKeyEventHandler if (!_mods.has(KeyValue.Modifier.SHIFT)) sel_start = sel_end; } - conn.setSelection(sel_start, sel_end); + if (!conn.setSelection(sel_start, sel_end)) + move_cursor_fallback(d); } /** Send arrow keys as a fallback for editors that do not support |
