am 196da4a7: Merge "Fix a bug where backspace would not delete the selection"
* commit '196da4a7be84bcb6f998b2c647dd9c8b4e15f950': Fix a bug where backspace would not delete the selectionmain
commit
dc490326d8
|
@ -203,9 +203,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private WordComposer mWordComposer = new WordComposer();
|
private WordComposer mWordComposer = new WordComposer();
|
||||||
|
|
||||||
private int mCorrectionMode;
|
private int mCorrectionMode;
|
||||||
|
|
||||||
// Keep track of the last selection range to decide if we need to show word alternatives
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
||||||
private int mLastSelectionStart;
|
private static final int NOT_A_CURSOR_POSITION = -1;
|
||||||
private int mLastSelectionEnd;
|
private int mLastSelectionStart = NOT_A_CURSOR_POSITION;
|
||||||
|
private int mLastSelectionEnd = NOT_A_CURSOR_POSITION;
|
||||||
|
|
||||||
// Whether we are expecting an onUpdateSelection event to fire. If it does when we don't
|
// Whether we are expecting an onUpdateSelection event to fire. If it does when we don't
|
||||||
// "expect" it, it means the user actually moved the cursor.
|
// "expect" it, it means the user actually moved the cursor.
|
||||||
|
@ -1400,11 +1402,31 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// suggestion (typed word). It's intentional to have made this
|
// suggestion (typed word). It's intentional to have made this
|
||||||
// inconsistent with backspacing after selecting other suggestions.
|
// inconsistent with backspacing after selecting other suggestions.
|
||||||
restartSuggestionsOnManuallyPickedTypedWord(ic);
|
restartSuggestionsOnManuallyPickedTypedWord(ic);
|
||||||
|
} else {
|
||||||
|
// Here we must check whether there is a selection. If so we should remove the
|
||||||
|
// selected text, otherwise we should just delete the character before the cursor.
|
||||||
|
if (mLastSelectionStart != mLastSelectionEnd) {
|
||||||
|
final int lengthToDelete = mLastSelectionEnd - mLastSelectionStart;
|
||||||
|
ic.setSelection(mLastSelectionEnd, mLastSelectionEnd);
|
||||||
|
ic.deleteSurroundingText(lengthToDelete, 0);
|
||||||
|
} else {
|
||||||
|
if (NOT_A_CURSOR_POSITION == mLastSelectionEnd) {
|
||||||
|
// We don't know whether there is a selection or not. We just send a false
|
||||||
|
// hardware key event and let TextView sort it out for us. The problem
|
||||||
|
// here is, this is asynchronous with respect to the input connection
|
||||||
|
// batch edit, so it may flicker. But this only ever happens if backspace
|
||||||
|
// is pressed just after the IME is invoked, and then again only once.
|
||||||
|
// TODO: add an API call that gets the selection indices. This is available
|
||||||
|
// to the IME in the general case via onUpdateSelection anyway, and would
|
||||||
|
// allow us to remove this race condition.
|
||||||
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
||||||
} else {
|
} else {
|
||||||
ic.deleteSurroundingText(1, 0);
|
ic.deleteSurroundingText(1, 0);
|
||||||
|
}
|
||||||
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
||||||
ic.deleteSurroundingText(1, 0);
|
ic.deleteSurroundingText(1, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (isSuggestionsRequested()) {
|
if (isSuggestionsRequested()) {
|
||||||
restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(ic);
|
restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(ic);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue