mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Fix a race condition, take 2.
Don't use absolute cursor positions when making edits, this leads to race conditions. This is a bit ugly and will need to be fixed soon. Plans are underway to clean this up. Bug: 12390573 Change-Id: I69c09fc41b979880d0800c55a710e39373287cff
This commit is contained in:
parent
1e7f2809d2
commit
e5cdcaff65
@ -685,6 +685,10 @@ public final class RichInputConnection {
|
|||||||
&& !settingsValues.isWordConnector(codePointBeforeCursor)) {
|
&& !settingsValues.isWordConnector(codePointBeforeCursor)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return isCursorFollowedByWordCharacter(settingsValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCursorFollowedByWordCharacter(final SettingsValues settingsValues) {
|
||||||
final CharSequence after = getTextAfterCursor(1, 0);
|
final CharSequence after = getTextAfterCursor(1, 0);
|
||||||
if (!TextUtils.isEmpty(after) && !settingsValues.isWordSeparator(after.charAt(0))
|
if (!TextUtils.isEmpty(after) && !settingsValues.isWordSeparator(after.charAt(0))
|
||||||
&& !settingsValues.isWordConnector(after.charAt(0))) {
|
&& !settingsValues.isWordConnector(after.charAt(0))) {
|
||||||
|
@ -813,7 +813,8 @@ public final class InputLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settingsValues.isSuggestionStripVisible()
|
if (settingsValues.isSuggestionStripVisible()
|
||||||
&& settingsValues.mCurrentLanguageHasSpaces) {
|
&& settingsValues.mCurrentLanguageHasSpaces
|
||||||
|
&& !mConnection.isCursorFollowedByWordCharacter(settingsValues)) {
|
||||||
restartSuggestionsOnWordTouchedByCursor(settingsValues,
|
restartSuggestionsOnWordTouchedByCursor(settingsValues,
|
||||||
deleteCountAtStart - mDeleteCount /* offset */,
|
deleteCountAtStart - mDeleteCount /* offset */,
|
||||||
true /* includeResumedWordInSuggestions */, keyboardSwitcher);
|
true /* includeResumedWordInSuggestions */, keyboardSwitcher);
|
||||||
@ -1113,11 +1114,19 @@ public final class InputLogic {
|
|||||||
keyboardSwitcher.getKeyboard());
|
keyboardSwitcher.getKeyboard());
|
||||||
mWordComposer.setCursorPositionWithinWord(
|
mWordComposer.setCursorPositionWithinWord(
|
||||||
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
||||||
// TODO: Change these two lines to setComposingRegion(cursorPosition,
|
// TODO: Change these lines to setComposingRegion(cursorPosition,
|
||||||
// cursorPosition + range.getNumberOfCharsInWordAfterCursor());
|
// cursorPosition + range.getNumberOfCharsInWordAfterCursor());
|
||||||
mConnection.deleteSurroundingText(numberOfCharsInWordBeforeCursor,
|
if (0 != offset) {
|
||||||
typedWord.length() - numberOfCharsInWordBeforeCursor);
|
// Backspace was pressed. We are at the end of a word, and we don't know the cursor
|
||||||
mConnection.setComposingText(typedWord, 1);
|
// position for sure, so use relative methods.
|
||||||
|
mConnection.deleteSurroundingText(numberOfCharsInWordBeforeCursor, 0);
|
||||||
|
mConnection.setComposingText(typedWord, 1);
|
||||||
|
} else {
|
||||||
|
// This is recorrection. The cursor position is reasonably reliable, and the cursor
|
||||||
|
// may be in the middle of a word so use setComposingRegion.
|
||||||
|
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
|
||||||
|
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
|
||||||
|
}
|
||||||
if (suggestions.isEmpty()) {
|
if (suggestions.isEmpty()) {
|
||||||
// We come here if there weren't any suggestion spans on this word. We will try to
|
// We come here if there weren't any suggestion spans on this word. We will try to
|
||||||
// compute suggestions for it instead.
|
// compute suggestions for it instead.
|
||||||
|
Loading…
Reference in New Issue
Block a user