the virtual arrow keys can now move the text cursor
This commit is contained in:
parent
a88e87da01
commit
0a1aed88d5
5 changed files with 63 additions and 4 deletions
|
|
@ -101,6 +101,11 @@ public abstract class HotkeyHandler extends CommandHandler {
|
|||
}
|
||||
|
||||
|
||||
public boolean onKeyMoveCursor(boolean backward) {
|
||||
return textField.moveCursor(backward);
|
||||
}
|
||||
|
||||
|
||||
public boolean onKeyFilterClear(boolean validateOnly) {
|
||||
if (suggestionOps.isEmpty()) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.text.Spannable;
|
|||
import android.text.SpannableString;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
|
|
@ -233,4 +234,21 @@ public class TextField extends InputField {
|
|||
|
||||
return styledWord;
|
||||
}
|
||||
|
||||
|
||||
public boolean moveCursor(boolean backward) {
|
||||
if (
|
||||
connection == null
|
||||
|| (backward && getStringBeforeCursor(1).isEmpty())
|
||||
|| (!backward && getStringAfterCursor(1).isEmpty())
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int keyCode = backward ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
||||
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,8 +151,6 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
|
||||
if (keyId == R.id.soft_key_add_word) { tt9.addWord(); return true; }
|
||||
if (keyId == R.id.soft_key_command_palette) return tt9.onKeyCommandPalette(false);
|
||||
if (keyId == R.id.soft_key_left_arrow) return tt9.onKeyScrollSuggestion(false, true);
|
||||
if (keyId == R.id.soft_key_right_arrow) return tt9.onKeyScrollSuggestion(false, false);
|
||||
if (keyId == R.id.soft_key_language) return tt9.onKeyNextLanguage(false);
|
||||
if (keyId == R.id.soft_key_settings) { tt9.showSettings(); return true; }
|
||||
if (keyId == R.id.soft_key_voice_input) { tt9.toggleVoiceInput(); return true; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package io.github.sspanak.tt9.ui.main.keys;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
|
||||
public class SoftKeyArrow extends SoftKey {
|
||||
public SoftKeyArrow(Context context) { super(context); }
|
||||
public SoftKeyArrow(Context context, AttributeSet attrs) { super(context, attrs); }
|
||||
public SoftKeyArrow(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
|
||||
|
||||
@Override
|
||||
protected boolean handleRelease() {
|
||||
return handleHold();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleHold() {
|
||||
if (!validateTT9Handler()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int keyId = getId();
|
||||
if (keyId == R.id.soft_key_left_arrow) return onLeft();
|
||||
if (keyId == R.id.soft_key_right_arrow) return onRight();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean onLeft() {
|
||||
return tt9.onKeyScrollSuggestion(false, true) || tt9.onKeyMoveCursor(true);
|
||||
}
|
||||
|
||||
private boolean onRight() {
|
||||
return tt9.onKeyScrollSuggestion(false, false) || tt9.onKeyMoveCursor(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
android:layout_height="@dimen/numpad_candidate_height"
|
||||
android:layoutDirection="ltr">
|
||||
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftKey
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftKeyArrow
|
||||
android:id="@+id/soft_key_left_arrow"
|
||||
style="@android:style/Widget.Holo.Button.Borderless"
|
||||
android:layout_width="@dimen/numpad_arrow_key_width"
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
android:id="@+id/separator_candidates_2"
|
||||
style="@style/numSeparator" />
|
||||
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftKey
|
||||
<io.github.sspanak.tt9.ui.main.keys.SoftKeyArrow
|
||||
android:id="@+id/soft_key_right_arrow"
|
||||
style="@android:style/Widget.Holo.Button.Borderless"
|
||||
android:layout_width="@dimen/numpad_arrow_key_width"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue