From 934dda062040b29992b2cc9d6a39fcb550bc8edd Mon Sep 17 00:00:00 2001 From: sspanak Date: Wed, 16 Oct 2024 15:21:51 +0300 Subject: [PATCH] fixed typing the preferred instead of the selected special character, when pressing 0, scrolling the suggestions, then pressing 0 again --- .../sspanak/tt9/ime/modes/ModePredictive.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModePredictive.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModePredictive.java index 9542c8bd..e8f1b79f 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModePredictive.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModePredictive.java @@ -432,10 +432,19 @@ public class ModePredictive extends InputMode { */ @Override public boolean shouldAcceptPreviousSuggestion(int nextKey) { + final char SPECIAL_CHARS_KEY = NaturalLanguage.SPECIAL_CHARS_KEY.charAt(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) { + return true; + } + return !digitSequence.isEmpty() && ( - (nextKey == 0 && digitSequence.charAt(digitSequence.length() - 1) != '0') - || (nextKey != 0 && digitSequence.charAt(digitSequence.length() - 1) == '0') + (nextKey == 0 && digitSequence.charAt(digitSequence.length() - 1) != SPECIAL_CHARS_KEY) + || (nextKey != 0 && digitSequence.charAt(digitSequence.length() - 1) == SPECIAL_CHARS_KEY) ); }