Skip to content

Commit 97802ea

Browse files
committed
feat: strip spaces before punctuation marks
1 parent 7cf14c6 commit 97802ea

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,33 @@ private boolean trySwapSwapperAndSpace(final Event event,
19691969
return true;
19701970
}
19711971

1972+
private static boolean isSpaceStrippingPunctuation(final int codePoint) {
1973+
return codePoint == '.'
1974+
|| codePoint == ','
1975+
|| codePoint == ';'
1976+
|| codePoint == ':'
1977+
|| codePoint == '!'
1978+
|| codePoint == '?'
1979+
|| codePoint == ')'
1980+
|| codePoint == ']'
1981+
|| codePoint == '}'
1982+
|| codePoint == '؟' // Arabic question mark
1983+
|| codePoint == '،' // Arabic comma
1984+
|| codePoint == '؛' // Arabic semicolon
1985+
|| codePoint == '।' // Hindi Danda
1986+
|| codePoint == '॥' // Hindi Double Danda
1987+
|| codePoint == '。' // CJK full stop
1988+
|| codePoint == '、' // CJK enumeration comma
1989+
|| codePoint == ',' // CJK fullwidth comma
1990+
|| codePoint == '?' // CJK fullwidth question mark
1991+
|| codePoint == '!' // CJK fullwidth exclamation mark
1992+
|| codePoint == ':' // CJK fullwidth colon
1993+
|| codePoint == ';' // CJK fullwidth semicolon
1994+
|| codePoint == ')' // CJK fullwidth closing parenthesis
1995+
|| codePoint == '】' // CJK fullwidth closing bracket
1996+
|| codePoint == '』'; // CJK fullwidth closing quote
1997+
}
1998+
19721999
/*
19732000
* Strip a trailing space if necessary and returns whether it's a swap weak
19742001
* space situation.
@@ -1988,6 +2015,14 @@ private boolean tryStripSpaceAndReturnWhetherShouldSwapInstead(final Event event
19882015
mConnection.removeTrailingSpace();
19892016
return false;
19902017
}
2018+
2019+
if (isSpaceStrippingPunctuation(codePoint)
2020+
&& !inputTransaction.getSettingsValues().isUsuallyPrecededBySpace(codePoint)) {
2021+
if (mConnection.getCodePointBeforeCursor() == Constants.CODE_SPACE) {
2022+
mConnection.removeTrailingSpace();
2023+
}
2024+
}
2025+
19912026
if ((SpaceState.WEAK == inputTransaction.getSpaceState()
19922027
|| SpaceState.SWAP_PUNCTUATION == inputTransaction.getSpaceState())
19932028
&& isFromSuggestionStrip) {

0 commit comments

Comments
 (0)