smooth language change is now possible to/from East Asian languages too
This commit is contained in:
parent
86a3274436
commit
d996b74b5e
6 changed files with 14 additions and 18 deletions
|
|
@ -308,7 +308,9 @@ public abstract class HotkeyHandler extends CommandHandler {
|
|||
if (mInputMode.changeLanguage(mLanguage)) {
|
||||
mInputMode.clearWordStem();
|
||||
} else {
|
||||
final String digits = mInputMode.getSequence();
|
||||
mInputMode = InputMode.getInstance(settings, mLanguage, inputType, textField, determineInputModeId());
|
||||
mInputMode.setSequence(digits);
|
||||
}
|
||||
|
||||
getSuggestions(null);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import io.github.sspanak.tt9.languages.LanguageCollection;
|
|||
import io.github.sspanak.tt9.languages.LanguageKind;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.UI;
|
||||
import io.github.sspanak.tt9.util.Text;
|
||||
|
||||
public abstract class TypingHandler extends KeyPadHandler {
|
||||
// internal settings/data
|
||||
|
|
@ -407,15 +406,6 @@ public abstract class TypingHandler extends KeyPadHandler {
|
|||
// display the word suggestions
|
||||
suggestionOps.set(mInputMode.getSuggestions(), mInputMode.containsGeneratedSuggestions());
|
||||
|
||||
// In case we are here, because the language was changed, and there were words for the old language,
|
||||
// but there are no words for the new language, we'll get only generated suggestions, consisting
|
||||
// of the last word of the previous language + endings from the new language. These words are invalid,
|
||||
// so we discard them.
|
||||
if (InputModeKind.isPredictive(mInputMode) && !mLanguage.isValidWord(suggestionOps.getCurrent()) && !Text.isGraphic(suggestionOps.getCurrent())) {
|
||||
mInputMode.reset();
|
||||
suggestionOps.set(null);
|
||||
}
|
||||
|
||||
// flush the first suggestion, if the InputMode has requested it
|
||||
if (suggestionOps.scheduleDelayedAccept(mInputMode.getAutoAcceptTimeout())) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -114,7 +114,8 @@ abstract public class InputMode {
|
|||
// Utility
|
||||
abstract public int getId();
|
||||
public boolean containsGeneratedSuggestions() { return false; }
|
||||
public String getSequence() { return digitSequence; }
|
||||
@NonNull public String getSequence() { return digitSequence; }
|
||||
public void setSequence(@NonNull String sequence) { digitSequence = sequence; }
|
||||
public int getSequenceLength() { return digitSequence.length(); } // The number of key presses for the current word.
|
||||
public int getAutoAcceptTimeout() {
|
||||
return autoAcceptTimeout;
|
||||
|
|
|
|||
|
|
@ -100,9 +100,9 @@ public class ModeIdeograms extends ModeWords {
|
|||
@Override
|
||||
public void onAcceptSuggestion(@NonNull String currentWord, boolean preserveWords) {
|
||||
final Text text = new Text(currentWord);
|
||||
if (text.isEmpty() || text.startsWithWhitespace() || text.isNumeric()) {
|
||||
if (text.isEmpty() || text.startsWithWhitespace() || text.isNumeric() || !language.isValidWord(currentWord)) {
|
||||
reset();
|
||||
Logger.i(LOG_TAG, "Current word is empty or numeric. Nothing to accept.");
|
||||
Logger.i(LOG_TAG, "Current word is empty, numeric or invalid. Nothing to accept.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ public class ModeIdeograms extends ModeWords {
|
|||
}
|
||||
|
||||
final int initialLength = digitSequence.length();
|
||||
final boolean lastDigitBelongsToNewWord = preserveWords && initialLength >= 2;
|
||||
boolean lastDigitBelongsToNewWord = preserveWords && initialLength >= 2;
|
||||
|
||||
try {
|
||||
if (!digitSequence.equals(SPECIAL_CHAR_SEQUENCE) && !digitSequence.equals(PUNCTUATION_SEQUENCE)) {
|
||||
|
|
@ -125,8 +125,8 @@ public class ModeIdeograms extends ModeWords {
|
|||
((IdeogramPredictions) predictions).onAcceptIdeogram(currentWord);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
lastAcceptedSequence = lastAcceptedWord = "";
|
||||
Logger.e(LOG_TAG, "Failed incrementing priority of word: '" + currentWord + "'. " + e.getMessage());
|
||||
lastAcceptedSequence = lastAcceptedWord = "";
|
||||
}
|
||||
|
||||
if (lastDigitBelongsToNewWord) {
|
||||
|
|
|
|||
|
|
@ -323,8 +323,8 @@ class ModeWords extends ModeCheonjiin {
|
|||
}
|
||||
stem = "";
|
||||
|
||||
if (currentWord.isEmpty()) {
|
||||
Logger.i(LOG_TAG, "Current word is empty. Nothing to accept.");
|
||||
if (currentWord.isEmpty() || !language.isValidWord(currentWord)) {
|
||||
Logger.i(LOG_TAG, "Current word is empty or invalid. Nothing to accept.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,12 +264,15 @@ public class NaturalLanguage extends TranscribedLanguage {
|
|||
if (
|
||||
word == null
|
||||
|| word.isEmpty()
|
||||
|| (super.isValidWord(word))
|
||||
|| (word.length() == 1 && Character.isDigit(word.charAt(0)))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isTranscribed) {
|
||||
return super.isValidWord(word);
|
||||
}
|
||||
|
||||
String lowerCaseWord = word.toLowerCase(locale);
|
||||
|
||||
for (int i = 0; i < lowerCaseWord.length(); i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue