1
0
Fork 0

fixed Ukrainian and Hebrew words incorrectly combining with all punctuation, instead of only apostrophes

This commit is contained in:
sspanak 2024-09-23 12:17:20 +03:00 committed by Dimo Karaivanov
parent 342ea1d3e5
commit 5bdde1c5a0
4 changed files with 26 additions and 10 deletions

View file

@ -357,7 +357,7 @@ public abstract class TypingHandler extends KeyPadHandler {
// Second pass, analyze the available suggestions and decide if combining them with the
// last key press makes up a compound word like: (it)'s, (I)'ve, l'(oiseau), or it is
// just the end of a sentence, like: "word." or "another?"
if (mInputMode.shouldAcceptPreviousSuggestion()) {
if (mInputMode.shouldAcceptPreviousSuggestion(suggestionOps.getCurrent())) {
String lastWord = suggestionOps.acceptPrevious(mInputMode.getSequenceLength());
onAcceptSuggestionAutomatically(lastWord);
}

View file

@ -104,7 +104,7 @@ abstract public class InputMode {
}
// Interaction with the IME. Return "true" if it should perform the respective action.
public boolean shouldAcceptPreviousSuggestion() { return false; }
public boolean shouldAcceptPreviousSuggestion(String unacceptedText) { return false; }
public boolean shouldAcceptPreviousSuggestion(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; }

View file

@ -99,8 +99,8 @@ public class ModeABC extends InputMode {
shouldSelectNextLetter = true; // do not accept any previous suggestions after loading the new ones
}
@Override public void onAcceptSuggestion(@NonNull String word) { reset(); }
@Override public boolean shouldAcceptPreviousSuggestion() { return !shouldSelectNextLetter; }
@Override public void onAcceptSuggestion(@NonNull String w) { reset(); }
@Override public boolean shouldAcceptPreviousSuggestion(String w) { return !shouldSelectNextLetter; }
@Override public boolean shouldSelectNextSuggestion() { return shouldSelectNextLetter; }
@Override

View file

@ -445,7 +445,7 @@ public class ModePredictive extends InputMode {
* Variant for post suggestion load analysis.
*/
@Override
public boolean shouldAcceptPreviousSuggestion() {
public boolean shouldAcceptPreviousSuggestion(String unacceptedText) {
// backspace never breaks words
if (!isCursorDirectionForward) {
return false;
@ -456,11 +456,8 @@ public class ModePredictive extends InputMode {
return true;
}
// allow apostrophes in the middle or at the end of Hebrew and Ukrainian words
if (LanguageKind.isHebrew(language) || LanguageKind.isUkrainian(language)) {
return
predictions.noDbWords()
&& digitSequence.equals(NaturalLanguage.PUNCTUATION_KEY);
if (shouldAcceptHebrewOrUkrainianWord(unacceptedText)) {
return true;
}
// punctuation breaks words, unless there are database matches ('s, qu', по-, etc...)
@ -473,6 +470,25 @@ public class ModePredictive extends InputMode {
}
/**
* Apostrophes never break Ukrainian and Hebrew words because they are used as letters. Same for
* the quotation marks in Hebrew.
*/
private boolean shouldAcceptHebrewOrUkrainianWord(String unacceptedText) {
char penultimateChar = unacceptedText.length() > 1 ? unacceptedText.charAt(unacceptedText.length() - 2) : 0;
if (LanguageKind.isHebrew(language) && predictions.noDbWords()) {
return penultimateChar != '\'' && penultimateChar != '"';
}
if (LanguageKind.isUkrainian(language) && predictions.noDbWords()) {
return penultimateChar != '\'';
}
return false;
}
@Override
public boolean shouldAddTrailingSpace(InputType inputType, TextField textField, boolean isWordAcceptedManually, int nextKey) {
return autoSpace.shouldAddTrailingSpace(textField, inputType, isWordAcceptedManually, nextKey);