From 5bdde1c5a01e54fbf2a38bd936ee04304979ad9f Mon Sep 17 00:00:00 2001 From: sspanak Date: Mon, 23 Sep 2024 12:17:20 +0300 Subject: [PATCH] fixed Ukrainian and Hebrew words incorrectly combining with all punctuation, instead of only apostrophes --- .../github/sspanak/tt9/ime/TypingHandler.java | 2 +- .../sspanak/tt9/ime/modes/InputMode.java | 2 +- .../github/sspanak/tt9/ime/modes/ModeABC.java | 4 +-- .../sspanak/tt9/ime/modes/ModePredictive.java | 28 +++++++++++++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java index 1a5f6d3e..02fb57e5 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java @@ -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); } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java index 195263f6..d31dce84 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/InputMode.java @@ -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; } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeABC.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeABC.java index 6199625a..44711213 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeABC.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeABC.java @@ -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 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 e14a29e9..28740e23 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 @@ -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);