fixed auto-space being incorrectly added after a newline and not added before a newline
This commit is contained in:
parent
d2b4b15def
commit
640f0f2ba8
3 changed files with 9 additions and 2 deletions
|
|
@ -136,11 +136,13 @@ public class AutoSpace {
|
||||||
* Similar to "shouldAddAfterPunctuation()", but determines whether to add a space after words.
|
* Similar to "shouldAddAfterPunctuation()", but determines whether to add a space after words.
|
||||||
*/
|
*/
|
||||||
private boolean shouldAddAfterWord(boolean isWordAcceptedManually, String previousChars, Text nextChars, int nextKey) {
|
private boolean shouldAddAfterWord(boolean isWordAcceptedManually, String previousChars, Text nextChars, int nextKey) {
|
||||||
|
char firstNextChar = nextChars.isEmpty() ? 0 : nextChars.toString().charAt(0);
|
||||||
|
|
||||||
return
|
return
|
||||||
isWordAcceptedManually // Do not add space when auto-accepting words, because it feels very confusing when typing.
|
isWordAcceptedManually // Do not add space when auto-accepting words, because it feels very confusing when typing.
|
||||||
&& isLanguageWithAlphabet
|
&& isLanguageWithAlphabet
|
||||||
&& nextKey != 1
|
&& nextKey != 1
|
||||||
&& nextChars.isEmpty()
|
&& (nextChars.isEmpty() || nextChars.startsWithNewline())
|
||||||
&& Text.previousIsLetter(previousChars);
|
&& Text.previousIsLetter(previousChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,11 @@ public class Text extends TextTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean startsWithNewline() {
|
||||||
|
return text != null && !text.isEmpty() && text.charAt(0) == '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean startsWithNumber() {
|
public boolean startsWithNumber() {
|
||||||
return text != null && !text.isEmpty() && Character.isDigit(text.charAt(0));
|
return text != null && !text.isEmpty() && Character.isDigit(text.charAt(0));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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_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 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 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+$");
|
private static final Pattern START_OF_SENTENCE = Pattern.compile("(?<!\\.)(^|[.?!؟¿¡])\\s+$");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue