am 9fe700ec: Merge "Fix moving the cursor inside composition in lang w/o spaces"

* commit '9fe700ec4fceba1e061733795bc89ca9d0620525':
  Fix moving the cursor inside composition in lang w/o spaces
main
Jean Chalard 2015-01-16 03:27:10 +00:00 committed by Android Git Automerger
commit a0b9e57af4
3 changed files with 45 additions and 2 deletions

View File

@ -58,6 +58,8 @@ public class Event {
final public static int EVENT_TYPE_SUGGESTION_PICKED = 5; final public static int EVENT_TYPE_SUGGESTION_PICKED = 5;
// An event corresponding to a string generated by some software process. // An event corresponding to a string generated by some software process.
final public static int EVENT_TYPE_SOFTWARE_GENERATED_STRING = 6; final public static int EVENT_TYPE_SOFTWARE_GENERATED_STRING = 6;
// An event corresponding to a cursor move
final public static int EVENT_TYPE_CURSOR_MOVE = 7;
// 0 is a valid code point, so we use -1 here. // 0 is a valid code point, so we use -1 here.
final public static int NOT_A_CODE_POINT = -1; final public static int NOT_A_CODE_POINT = -1;
@ -233,6 +235,18 @@ public class Event {
null /* next */); null /* next */);
} }
/**
* Creates an input event representing moving the cursor. The relative move amount is stored
* in mX.
* @param moveAmount the relative move amount.
* @return an event for this cursor move.
*/
@Nonnull
public static Event createCursorMovedEvent(final int moveAmount) {
return new Event(EVENT_TYPE_CURSOR_MOVE, null, NOT_A_CODE_POINT, NOT_A_KEY_CODE,
moveAmount, Constants.NOT_A_COORDINATE, null, FLAG_NONE, null);
}
/** /**
* Creates an event identical to the passed event, but that has already been consumed. * Creates an event identical to the passed event, but that has already been consumed.
* @param source the event to copy the properties of. * @param source the event to copy the properties of.
@ -291,6 +305,7 @@ public class Event {
case EVENT_TYPE_MODE_KEY: case EVENT_TYPE_MODE_KEY:
case EVENT_TYPE_NOT_HANDLED: case EVENT_TYPE_NOT_HANDLED:
case EVENT_TYPE_TOGGLE: case EVENT_TYPE_TOGGLE:
case EVENT_TYPE_CURSOR_MOVE:
return ""; return "";
case EVENT_TYPE_INPUT_KEYPRESS: case EVENT_TYPE_INPUT_KEYPRESS:
return StringUtils.newSingleCodePointString(mCodePoint); return StringUtils.newSingleCodePointString(mCodePoint);

View File

@ -231,8 +231,6 @@ public final class WordComposer {
* @return true if the cursor is still inside the composing word, false otherwise. * @return true if the cursor is still inside the composing word, false otherwise.
*/ */
public boolean moveCursorByAndReturnIfInsideComposingWord(final int expectedMoveAmount) { public boolean moveCursorByAndReturnIfInsideComposingWord(final int expectedMoveAmount) {
// TODO: should uncommit the composing feedback
mCombinerChain.reset();
int actualMoveAmountWithinWord = 0; int actualMoveAmountWithinWord = 0;
int cursorPos = mCursorPositionWithinWord; int cursorPos = mCursorPositionWithinWord;
// TODO: Don't make that copy. We can do this directly from mTypedWordCache. // TODO: Don't make that copy. We can do this directly from mTypedWordCache.
@ -256,6 +254,8 @@ public final class WordComposer {
// so the result would not be inside the composing word. // so the result would not be inside the composing word.
if (actualMoveAmountWithinWord != expectedMoveAmount) return false; if (actualMoveAmountWithinWord != expectedMoveAmount) return false;
mCursorPositionWithinWord = cursorPos; mCursorPositionWithinWord = cursorPos;
mCombinerChain.applyProcessedEvent(mCombinerChain.processEvent(mEvents,
Event.createCursorMovedEvent(cursorPos)));
return true; return true;
} }

View File

@ -89,6 +89,34 @@ public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase {
BaseInputConnection.getComposingSpanEnd(mEditText.getText())); BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
} }
public void testMovingCursorInsideWordAndType() {
final String WORD_TO_TYPE = "abcdefgh";
final int typedLength = WORD_TO_TYPE.length();
final int CURSOR_POS = 4;
changeKeyboardLocaleAndDictLocale("th", "en_US");
type(WORD_TO_TYPE);
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, 0, typedLength);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
mInputConnection.setSelection(CURSOR_POS, CURSOR_POS);
mLatinIME.onUpdateSelection(typedLength, typedLength,
CURSOR_POS, CURSOR_POS, 0, typedLength);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
assertEquals("move cursor inside text", 0,
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
assertEquals("move cursor inside text", typedLength,
BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
type("x");
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages();
assertEquals("start typing while cursor inside composition", CURSOR_POS,
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
assertEquals("start typing while cursor inside composition", CURSOR_POS + 1,
BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
}
public void testPredictions() { public void testPredictions() {
final String WORD_TO_TYPE = "Barack "; final String WORD_TO_TYPE = "Barack ";
changeKeyboardLocaleAndDictLocale("th", "en_US"); changeKeyboardLocaleAndDictLocale("th", "en_US");