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. // instead of requiring "OK" before that.
// First pass, analyze the incoming key press and decide whether it could be the start of // First pass, analyze the incoming key press and decide whether it could be the start of
// a new word. // a new word.
if (mInputMode.shouldAcceptPreviousSuggestion(key)) { if (mInputMode.shouldAcceptPreviousSuggestion(key, hold)) {
String lastWord = suggestionOps.acceptIncomplete(); String lastWord = suggestionOps.acceptIncomplete();
mInputMode.onAcceptSuggestion(lastWord); mInputMode.onAcceptSuggestion(lastWord);
autoCorrectSpace(lastWord, false, key); 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. // Interaction with the IME. Return "true" if it should perform the respective action.
public boolean shouldAcceptPreviousSuggestion(String unacceptedText) { return false; } 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 shouldAddTrailingSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int nextKey) { return false; }
public boolean shouldAddPrecedingSpace(InputType inputType, TextField textField) { return false; } public boolean shouldAddPrecedingSpace(InputType inputType, TextField textField) { return false; }
public boolean shouldDeletePrecedingSpace(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; 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; return false;
} }

View file

@ -17,7 +17,7 @@ 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 digitSequence.length(); } @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 ArrayList<ArrayList<String>> KEY_CHARACTERS = new ArrayList<>();
private final boolean isEmailMode; private final boolean isEmailMode;
@ -60,7 +60,7 @@ public class Mode123 extends ModePassthrough {
@Override protected boolean nextSpecialCharacters() { @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; return false;
} }

View file

@ -77,7 +77,7 @@ public class ModeABC extends InputMode {
@Override @Override
protected boolean nextSpecialCharacters() { 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')); suggestions.add(language.getKeyNumber(digitSequence.charAt(0) - '0'));
return true; return true;
} }

View file

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

View file

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