1
0
Fork 0

fixed auto-space being incorrectly added after a newline and not added before a newline

This commit is contained in:
sspanak 2025-04-14 17:53:17 +03:00 committed by Dimo Karaivanov
parent d2b4b15def
commit 640f0f2ba8
3 changed files with 9 additions and 2 deletions

View file

@ -136,11 +136,13 @@ public class AutoSpace {
* Similar to "shouldAddAfterPunctuation()", but determines whether to add a space after words.
*/
private boolean shouldAddAfterWord(boolean isWordAcceptedManually, String previousChars, Text nextChars, int nextKey) {
char firstNextChar = nextChars.isEmpty() ? 0 : nextChars.toString().charAt(0);
return
isWordAcceptedManually // Do not add space when auto-accepting words, because it feels very confusing when typing.
&& isLanguageWithAlphabet
&& nextKey != 1
&& nextChars.isEmpty()
&& (nextChars.isEmpty() || nextChars.startsWithNewline())
&& Text.previousIsLetter(previousChars);
}

View file

@ -221,6 +221,11 @@ public class Text extends TextTools {
}
public boolean startsWithNewline() {
return text != null && !text.isEmpty() && text.charAt(0) == '\n';
}
public boolean startsWithNumber() {
return text != null && !text.isEmpty() && Character.isDigit(text.charAt(0));
}

View file

@ -18,7 +18,7 @@ public class TextTools {
private static final Pattern IS_JAPANESE = Pattern.compile("\\p{script=Hiragana}+|\\p{script=Katakana}+|\\p{script=Han}+");
private static final Pattern IS_HANGUL = Pattern.compile("[\u1100-\u11FF\u302E-\u302F\u3131-\u318F\u3200-\u321F\u3260-\u327E\uA960-\uA97F\uAC00-\uD7FB\uFFA0-\uFFDF]+");
private static final Pattern NEXT_TO_WORD = Pattern.compile("\\b$");
private static final Pattern PREVIOUS_IS_LETTER = Pattern.compile("[\\p{L}\\p{M}]$");
private static final Pattern PREVIOUS_IS_LETTER = Pattern.compile("[\\p{L}\\p{M}](?!\\n)$");
private static final Pattern START_OF_SENTENCE = Pattern.compile("(?<!\\.)(^|[.?!؟¿¡])\\s+$");