1
0
Fork 0

fixed holding 0-key to to type a zero after a space erasing the space (in Predictive Mode)

This commit is contained in:
sspanak 2024-10-16 15:48:25 +03:00 committed by Dimo Karaivanov
parent 934dda0620
commit c55224351f
6 changed files with 20 additions and 20 deletions

View file

@ -174,7 +174,7 @@ public abstract class TypingHandler extends KeyPadHandler {
// instead of requiring "OK" before that.
// First pass, analyze the incoming key press and decide whether it could be the start of
// a new word.
if (mInputMode.shouldAcceptPreviousSuggestion(key)) {
if (mInputMode.shouldAcceptPreviousSuggestion(key, hold)) {
String lastWord = suggestionOps.acceptIncomplete();
mInputMode.onAcceptSuggestion(lastWord);
autoCorrectSpace(lastWord, false, key);

View file

@ -111,7 +111,7 @@ abstract public class InputMode {
// Interaction with the IME. Return "true" if it should perform the respective action.
public boolean shouldAcceptPreviousSuggestion(String unacceptedText) { return false; }
public boolean shouldAcceptPreviousSuggestion(int nextKey) { return false; }
public boolean shouldAcceptPreviousSuggestion(int nextKey, boolean hold) { return false; }
public boolean shouldAddTrailingSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int nextKey) { return false; }
public boolean shouldAddPrecedingSpace(InputType inputType, TextField textField) { return false; }
public boolean shouldDeletePrecedingSpace(InputType inputType, TextField textField) { return false; }
@ -150,7 +150,7 @@ abstract public class InputMode {
return true;
}
if (!language.hasUpperCase() || digitSequence.startsWith(NaturalLanguage.PUNCTUATION_KEY) || digitSequence.startsWith(NaturalLanguage.SPECIAL_CHARS_KEY)) {
if (!language.hasUpperCase() || digitSequence.startsWith(NaturalLanguage.PUNCTUATION_KEY) || digitSequence.startsWith(NaturalLanguage.SPECIAL_CHAR_KEY)) {
return false;
}

View file

@ -17,7 +17,7 @@ public class Mode123 extends ModePassthrough {
@Override public final boolean is123() { return true; }
@Override public boolean isPassthrough() { return false; }
@Override public int getSequenceLength() { return digitSequence.length(); }
@Override public boolean shouldAcceptPreviousSuggestion(int nextKey) { return true; }
@Override public boolean shouldAcceptPreviousSuggestion(int nextKey, boolean hold) { return true; }
private final ArrayList<ArrayList<String>> KEY_CHARACTERS = new ArrayList<>();
private final boolean isEmailMode;
@ -60,7 +60,7 @@ public class Mode123 extends ModePassthrough {
@Override protected boolean nextSpecialCharacters() {
if (isEmailMode || !digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) || !super.nextSpecialCharacters()) {
if (isEmailMode || !digitSequence.equals(NaturalLanguage.SPECIAL_CHAR_KEY) || !super.nextSpecialCharacters()) {
return false;
}

View file

@ -77,7 +77,7 @@ public class ModeABC extends InputMode {
@Override
protected boolean nextSpecialCharacters() {
if (KEY_CHARACTERS.isEmpty() && digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters()) {
if (KEY_CHARACTERS.isEmpty() && digitSequence.equals(NaturalLanguage.SPECIAL_CHAR_KEY) && super.nextSpecialCharacters()) {
suggestions.add(language.getKeyNumber(digitSequence.charAt(0) - '0'));
return true;
}

View file

@ -293,7 +293,7 @@ public class ModePredictive extends InputMode {
* options for the current digitSequence.
*/
private boolean loadStaticSuggestions() {
if (digitSequence.equals(NaturalLanguage.PUNCTUATION_KEY) || digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY)) {
if (digitSequence.equals(NaturalLanguage.PUNCTUATION_KEY) || digitSequence.equals(NaturalLanguage.SPECIAL_CHAR_KEY)) {
loadSpecialCharacters();
onSuggestionsUpdated.run();
return true;
@ -377,7 +377,7 @@ public class ModePredictive extends InputMode {
// punctuation and special chars are not in the database, so there is no point in
// running queries that would update nothing
if (!sequence.equals(NaturalLanguage.PUNCTUATION_KEY) && !sequence.startsWith(NaturalLanguage.SPECIAL_CHARS_KEY)) {
if (!sequence.equals(NaturalLanguage.PUNCTUATION_KEY) && !sequence.startsWith(NaturalLanguage.SPECIAL_CHAR_KEY)) {
predictions.onAccept(currentWord, sequence);
}
} catch (Exception e) {
@ -403,7 +403,7 @@ public class ModePredictive extends InputMode {
@Override
protected boolean nextSpecialCharacters() {
return digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY) && super.nextSpecialCharacters();
return digitSequence.equals(NaturalLanguage.SPECIAL_CHAR_KEY) && super.nextSpecialCharacters();
}
@Override
@ -431,20 +431,25 @@ public class ModePredictive extends InputMode {
* automatically. This is used for analysis before processing the incoming pressed key.
*/
@Override
public boolean shouldAcceptPreviousSuggestion(int nextKey) {
final char SPECIAL_CHARS_KEY = NaturalLanguage.SPECIAL_CHARS_KEY.charAt(0);
public boolean shouldAcceptPreviousSuggestion(int nextKey, boolean hold) {
if (hold) {
return true;
}
final char SPECIAL_CHAR_KEY_CODE = NaturalLanguage.SPECIAL_CHAR_KEY.charAt(0);
final int SPECIAL_CHAR_KEY = SPECIAL_CHAR_KEY_CODE - '0';
// Prevent typing the preferred character when the user has scrolled the special char suggestions.
// For example, it makes more sense to allow typing "+ " with 0 + scroll + 0, instead of clearing
// the "+" and replacing it with the preferred character.
if (!stem.isEmpty() && nextKey == SPECIAL_CHARS_KEY - '0' && digitSequence.charAt(0) == SPECIAL_CHARS_KEY) {
if (!stem.isEmpty() && nextKey == SPECIAL_CHAR_KEY && digitSequence.charAt(0) == SPECIAL_CHAR_KEY_CODE) {
return true;
}
return
!digitSequence.isEmpty() && (
(nextKey == 0 && digitSequence.charAt(digitSequence.length() - 1) != SPECIAL_CHARS_KEY)
|| (nextKey != 0 && digitSequence.charAt(digitSequence.length() - 1) == SPECIAL_CHARS_KEY)
(nextKey == SPECIAL_CHAR_KEY && digitSequence.charAt(digitSequence.length() - 1) != SPECIAL_CHAR_KEY_CODE)
|| (nextKey != SPECIAL_CHAR_KEY && digitSequence.charAt(digitSequence.length() - 1) == SPECIAL_CHAR_KEY_CODE)
);
}
@ -460,11 +465,6 @@ public class ModePredictive extends InputMode {
return false;
}
// special characters always break words
if (autoAcceptTimeout == 0 && !digitSequence.startsWith(NaturalLanguage.SPECIAL_CHARS_KEY)) {
return true;
}
if (shouldAcceptHebrewOrUkrainianWord(unacceptedText)) {
return true;
}

View file

@ -12,7 +12,7 @@ import io.github.sspanak.tt9.util.Text;
public class NaturalLanguage extends Language implements Comparable<NaturalLanguage> {
final public static String SPECIAL_CHARS_KEY = "0";
final public static String SPECIAL_CHAR_KEY = "0";
final public static String PUNCTUATION_KEY = "1";
final public static String PREFERRED_CHAR_SEQUENCE = "00";