1
0
Fork 0

restricted the text case changes at the beginning of a sentence, when 'Automatic Capitalisation' option is on

This commit is contained in:
sspanak 2025-06-17 21:59:45 +03:00 committed by Dimo Karaivanov
parent ee19f08b43
commit 7a0d4b7fb8
2 changed files with 23 additions and 3 deletions

View file

@ -385,11 +385,10 @@ class ModeWords extends ModeCheonjiin {
public boolean nextTextCase(boolean analyzeSurroundingText) { public boolean nextTextCase(boolean analyzeSurroundingText) {
boolean changed = super.nextTextCase(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 // "analyzeSurroundingText" is true only when Shift is pressed to avoid expensive
// calls to getStringBeforeCursor(). // calls to getStringBeforeCursor().
if (analyzeSurroundingText && textCase == CASE_LOWER && language.hasUpperCase() && settings.getAutoCapitalsAfterNewline() && textField.getStringBeforeCursor(1).equals("\n")) { if (analyzeSurroundingText && textCase == CASE_LOWER && autoTextCase.isLowerCaseForbidden(language, textField.getStringBeforeCursor())) {
changed = super.nextTextCase(analyzeSurroundingText); changed = super.nextTextCase(true);
} }
// since it's a user's choice, the default matters no more // since it's a user's choice, the default matters no more

View file

@ -88,4 +88,25 @@ public class AutoTextCase {
return InputMode.CASE_DICTIONARY; 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;
}
} }