Correct special space handling of punctuation
This fixes two defects: - One where some separators should promote a phantom space to a real space. This bug had a unit test but wasn't tracked. - One where French punctuations would behave incorrectly. Tracked Bug: 6113693 Change-Id: Ia7f86fc960e00141757632ab2c9bce9168dd6966main
parent
e31060dc77
commit
00ed3be95c
|
@ -19,11 +19,11 @@
|
|||
-->
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<!-- Symbols that should be swapped with a magic space -->
|
||||
<string name="magic_space_swapping_symbols">.,\")]}</string>
|
||||
<string name="weak_space_swapping_symbols">.,\")]}</string>
|
||||
<!-- Symbols that should strip a magic space -->
|
||||
<string name="magic_space_stripping_symbols">"	 \'\n-/_"</string>
|
||||
<string name="weak_space_stripping_symbols">"	 \'\n-/_"</string>
|
||||
<!-- Symbols that should promote magic spaces into real space -->
|
||||
<string name="magic_space_promoting_symbols">;:!?([*&@{<>+=|</string>
|
||||
<string name="phantom_space_promoting_symbols">;:!?([*&@{<>+=|</string>
|
||||
<!-- Symbols that do NOT separate words -->
|
||||
<string name="symbols_excluded_from_word_separators">\'</string>
|
||||
</resources>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<!-- Symbols that should strip a weak space -->
|
||||
<string name="weak_space_stripping_symbols">"	 \n/_\'-"</string>
|
||||
<!-- Symbols that should convert weak spaces into real space -->
|
||||
<string name="weak_space_promoting_symbols">([*&@{<>+=|</string>
|
||||
<string name="phantom_space_promoting_symbols">([*&@{<>+=|</string>
|
||||
<!-- Symbols that do NOT separate words -->
|
||||
<string name="symbols_excluded_from_word_separators">\'-</string>
|
||||
<!-- Word separator list is the union of all symbols except those that are not separators:
|
||||
|
|
|
@ -1610,6 +1610,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
final boolean swapWeakSpace = maybeStripSpaceWhileInBatchEdit(ic, primaryCode, spaceState,
|
||||
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
|
||||
|
||||
if (SPACE_STATE_PHANTOM == spaceState &&
|
||||
mSettingsValues.isPhantomSpacePromotingSymbol(primaryCode)) {
|
||||
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
||||
}
|
||||
sendKeyCodePoint(primaryCode);
|
||||
|
||||
if (Keyboard.CODE_SPACE == primaryCode) {
|
||||
|
|
|
@ -37,6 +37,7 @@ public class SettingsValues {
|
|||
public final int mDelayUpdateOldSuggestions;
|
||||
public final String mWeakSpaceStrippers;
|
||||
public final String mWeakSpaceSwappers;
|
||||
private final String mPhantomSpacePromotingSymbols;
|
||||
private final String mSuggestPuncs;
|
||||
public final SuggestedWords mSuggestPuncList;
|
||||
public final SuggestedWords mSuggestPuncOutputTextList;
|
||||
|
@ -91,6 +92,7 @@ public class SettingsValues {
|
|||
mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
|
||||
mWeakSpaceStrippers = res.getString(R.string.weak_space_stripping_symbols);
|
||||
mWeakSpaceSwappers = res.getString(R.string.weak_space_swapping_symbols);
|
||||
mPhantomSpacePromotingSymbols = res.getString(R.string.phantom_space_promoting_symbols);
|
||||
if (LatinImeLogger.sDBG) {
|
||||
final int length = mWeakSpaceStrippers.length();
|
||||
for (int i = 0; i < length; i = mWeakSpaceStrippers.offsetByCodePoints(i, 1)) {
|
||||
|
@ -192,7 +194,7 @@ public class SettingsValues {
|
|||
final String weakSpaceSwappers, final String symbolsExcludedFromWordSeparators,
|
||||
final Resources res) {
|
||||
String wordSeparators = weakSpaceStrippers + weakSpaceSwappers
|
||||
+ res.getString(R.string.weak_space_promoting_symbols);
|
||||
+ res.getString(R.string.phantom_space_promoting_symbols);
|
||||
for (int i = symbolsExcludedFromWordSeparators.length() - 1; i >= 0; --i) {
|
||||
wordSeparators = wordSeparators.replace(
|
||||
symbolsExcludedFromWordSeparators.substring(i, i + 1), "");
|
||||
|
@ -225,6 +227,11 @@ public class SettingsValues {
|
|||
return mWeakSpaceSwappers.contains(String.valueOf((char)code));
|
||||
}
|
||||
|
||||
public boolean isPhantomSpacePromotingSymbol(int code) {
|
||||
// TODO: this does not work if the code does not fit in a char
|
||||
return mPhantomSpacePromotingSymbols.contains(String.valueOf((char)code));
|
||||
}
|
||||
|
||||
private static boolean isAutoCorrectEnabled(final Resources resources,
|
||||
final String currentAutoCorrectionSetting) {
|
||||
final String autoCorrectionOff = resources.getString(
|
||||
|
|
Loading…
Reference in New Issue