diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeWords.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeWords.java index 35247b73..d14b0fb0 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeWords.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/ModeWords.java @@ -385,11 +385,10 @@ class ModeWords extends ModeCheonjiin { public boolean nextTextCase(boolean analyzeSurroundingText) { boolean changed = super.nextTextCase(analyzeSurroundingText); - // Prevent lowercase at the beginning of a line when the respective setting is enabled. // "analyzeSurroundingText" is true only when Shift is pressed to avoid expensive // calls to getStringBeforeCursor(). - if (analyzeSurroundingText && textCase == CASE_LOWER && language.hasUpperCase() && settings.getAutoCapitalsAfterNewline() && textField.getStringBeforeCursor(1).equals("\n")) { - changed = super.nextTextCase(analyzeSurroundingText); + if (analyzeSurroundingText && textCase == CASE_LOWER && autoTextCase.isLowerCaseForbidden(language, textField.getStringBeforeCursor())) { + changed = super.nextTextCase(true); } // since it's a user's choice, the default matters no more diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java index 14a1855e..71268a4c 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java @@ -88,4 +88,25 @@ public class AutoTextCase { return InputMode.CASE_DICTIONARY; } + + + /** + * Prevent lowercase at the beginning of a line when the respective setting is enabled, + * or at the beginning of a sentence, when auto capitalization is enabled. + */ + public boolean isLowerCaseForbidden(@NonNull Language language, @NonNull String beforeCursor) { + if (!language.hasUpperCase()) { + return false; + } + + if (settings.getAutoTextCase() && (beforeCursor.isEmpty() || Text.isStartOfSentence(beforeCursor))) { + return true; + } + + if (settings.getAutoCapitalsAfterNewline() && beforeCursor.endsWith("\n")) { + return true; + } + + return false; + } }