Fix a bug in the cached cursor pos, and simplify selection handling
The documentation for setComposingRegion states explicitly that it does not move the cursor. This is just a bug. This does not have any ill effects right now, but it will have in later changes if not fixed. As for the selection handling, the specific test that this code removes used to serve a purpose, but it does not any more because the code using the value has been much sanitized. Now the variable can just take the obvious value, and become so self-explanatory that the comments are unnecessary. Change-Id: I548d899b38776bd3ab5f5361aab0d89d98f12e73main
parent
0c178ffc8e
commit
e5dee0af4a
|
@ -884,19 +884,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor the following code to be less contrived.
|
final boolean selectionChanged = mLastSelectionStart != newSelStart
|
||||||
// "newSelStart != composingSpanEnd" || "newSelEnd != composingSpanEnd" means
|
|| mLastSelectionEnd != newSelEnd;
|
||||||
// that the cursor is not at the end of the composing span, or there is a selection.
|
|
||||||
// "mLastSelectionStart != newSelStart" means that the cursor is not in the same place
|
|
||||||
// as last time we were called (if there is a selection, it means the start hasn't
|
|
||||||
// changed, so it's the end that did).
|
|
||||||
final boolean selectionChanged = (newSelStart != composingSpanEnd
|
|
||||||
|| newSelEnd != composingSpanEnd) && mLastSelectionStart != newSelStart;
|
|
||||||
// if composingSpanStart and composingSpanEnd are -1, it means there is no composing
|
// if composingSpanStart and composingSpanEnd are -1, it means there is no composing
|
||||||
// span in the view - we can use that to narrow down whether the cursor was moved
|
// span in the view - we can use that to narrow down whether the cursor was moved
|
||||||
// by us or not. If we are composing a word but there is no composing span, then
|
// by us or not. If we are composing a word but there is no composing span, then
|
||||||
// we know for sure the cursor moved while we were composing and we should reset
|
// we know for sure the cursor moved while we were composing and we should reset
|
||||||
// the state.
|
// the state. TODO: rescind this policy: the framework never removes the composing
|
||||||
|
// span on its own accord while editing. This test is useless.
|
||||||
|
|
||||||
final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
|
final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
|
||||||
// If the keyboard is not visible, we don't need to do all the housekeeping work, as it
|
// If the keyboard is not visible, we don't need to do all the housekeeping work, as it
|
||||||
// will be reset when the keyboard shows up anyway.
|
// will be reset when the keyboard shows up anyway.
|
||||||
|
@ -937,6 +933,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
if (isSuggestionsStripVisible()) {
|
if (isSuggestionsStripVisible()) {
|
||||||
mHandler.postResumeSuggestions();
|
mHandler.postResumeSuggestions();
|
||||||
}
|
}
|
||||||
|
mConnection.userMovedCursor(newSelEnd);
|
||||||
// Reset the last recapitalization.
|
// Reset the last recapitalization.
|
||||||
mRecapitalizeStatus.deactivate();
|
mRecapitalizeStatus.deactivate();
|
||||||
mKeyboardSwitcher.updateShiftState();
|
mKeyboardSwitcher.updateShiftState();
|
||||||
|
|
|
@ -338,7 +338,6 @@ public final class RichInputConnection {
|
||||||
public void setComposingRegion(final int start, final int end) {
|
public void setComposingRegion(final int start, final int end) {
|
||||||
if (DEBUG_BATCH_NESTING) checkBatchEdit();
|
if (DEBUG_BATCH_NESTING) checkBatchEdit();
|
||||||
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
|
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
|
||||||
mCurrentCursorPosition = end;
|
|
||||||
final CharSequence textBeforeCursor =
|
final CharSequence textBeforeCursor =
|
||||||
getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE + (end - start), 0);
|
getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE + (end - start), 0);
|
||||||
mCommittedTextBeforeComposingText.setLength(0);
|
mCommittedTextBeforeComposingText.setLength(0);
|
||||||
|
@ -722,6 +721,14 @@ public final class RichInputConnection {
|
||||||
return (newSelStart - oldSelStart) * (mCurrentCursorPosition - newSelStart) >= 0;
|
return (newSelStart - oldSelStart) * (mCurrentCursorPosition - newSelStart) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user moved the cursor by hand. Take a note of it.
|
||||||
|
* @param newCursorPosition The new cursor position.
|
||||||
|
*/
|
||||||
|
public void userMovedCursor(final int newCursorPosition) {
|
||||||
|
mCurrentCursorPosition = newCursorPosition;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks at the text just before the cursor to find out if it looks like a URL.
|
* Looks at the text just before the cursor to find out if it looks like a URL.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue