1
0
Fork 0

fixed backspace not working in constrained input fields where composing text can not be displayed

This commit is contained in:
sspanak 2024-04-17 17:19:13 +03:00 committed by Dimo Karaivanov
parent b39204609a
commit a42c1ed1ee
5 changed files with 27 additions and 8 deletions

View file

@ -85,6 +85,10 @@ public class SuggestionOps {
String acceptPrevious(int sequenceLength) { String acceptPrevious(int sequenceLength) {
if (sequenceLength <= 0) {
set(null);
}
String lastComposingText = getCurrent(sequenceLength - 1); String lastComposingText = getCurrent(sequenceLength - 1);
commitCurrent(false); commitCurrent(false);
return lastComposingText; return lastComposingText;

View file

@ -98,6 +98,7 @@ public abstract class TypingHandler extends KeyPadHandler {
} }
@Override
public boolean onBackspace() { public boolean onBackspace() {
// Dialer fields seem to handle backspace on their own and we must ignore it, // Dialer fields seem to handle backspace on their own and we must ignore it,
// otherwise, keyDown race condition occur for all keys. // otherwise, keyDown race condition occur for all keys.
@ -105,9 +106,7 @@ public abstract class TypingHandler extends KeyPadHandler {
return false; return false;
} }
// * Some app may need special treatment, so let them be. if (appHacks.onBackspace(mInputMode)) {
// * When there is no text, allow double function keys to function normally (e.g. "Back" navigates back)
if (appHacks.onBackspace(mInputMode) || textField.getStringBeforeCursor(1).isEmpty()) {
mInputMode.reset(); mInputMode.reset();
return false; return false;
} }

View file

@ -138,10 +138,11 @@ public class AppHacks {
if (isKindleInvertedTextField()) { if (isKindleInvertedTextField()) {
inputMode.clearWordStem(); inputMode.clearWordStem();
} else if (isTermux()) { } else if (isTermux()) {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL); return false;
} }
return false; // When there is no text, allow double function keys to function normally (e.g. "Back" navigates back)
return inputMode.getSuggestions().isEmpty() && textField.getStringBeforeCursor(1).isEmpty();
} }

View file

@ -17,7 +17,6 @@ public class Mode123 extends ModePassthrough {
@Override public final boolean is123() { return true; } @Override public final boolean is123() { return true; }
@Override public boolean isPassthrough() { return false; } @Override public boolean isPassthrough() { return false; }
@Override public int getSequenceLength() { return 1; }
@Override public boolean shouldAcceptPreviousSuggestion(int nextKey) { return true; } @Override public boolean shouldAcceptPreviousSuggestion(int nextKey) { return true; }
private final ArrayList<ArrayList<String>> KEY_CHARACTERS = new ArrayList<>(); private final ArrayList<ArrayList<String>> KEY_CHARACTERS = new ArrayList<>();
@ -86,6 +85,16 @@ public class Mode123 extends ModePassthrough {
return digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters(); return digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters();
} }
@Override public boolean onBackspace() {
if (suggestions.isEmpty()) {
return false;
}
reset();
return true;
}
@Override public boolean onNumber(int number, boolean hold, int repeat) { @Override public boolean onNumber(int number, boolean hold, int repeat) {
reset(); reset();
digitSequence = String.valueOf(number); digitSequence = String.valueOf(number);
@ -100,7 +109,6 @@ public class Mode123 extends ModePassthrough {
return true; return true;
} }
/** /**
* shouldIgnoreText * shouldIgnoreText
* Since this is a numeric mode, we allow typing only numbers and: * Since this is a numeric mode, we allow typing only numbers and:
@ -120,6 +128,9 @@ public class Mode123 extends ModePassthrough {
); );
} }
@Override public void onAcceptSuggestion(@NonNull String ignored, boolean ignored2) {
reset();
}
@Override public void reset() { @Override public void reset() {
super.reset(); super.reset();

View file

@ -20,8 +20,12 @@ public class ModeABC extends InputMode {
@Override @Override
public boolean onBackspace() { public boolean onBackspace() {
if (suggestions.isEmpty()) {
return false;
}
reset(); reset();
return false; return true;
} }
@Override @Override