diff options
author | 2015-02-27 18:36:42 +0000 | |
---|---|---|
committer | 2015-02-27 18:36:42 +0000 | |
commit | 29de00a52da9fadaa9d490d9535120793d0e142c (patch) | |
tree | d0841e5150a64efc669364362a94a93f0b7fa4ae /java/src | |
parent | 7d5cbb611e82e412fc1486178c5196ff75673863 (diff) | |
parent | 69c04cadc7c017f9de53f13ea045347b80316d4a (diff) | |
download | latinime-29de00a52da9fadaa9d490d9535120793d0e142c.tar.gz latinime-29de00a52da9fadaa9d490d9535120793d0e142c.tar.xz latinime-29de00a52da9fadaa9d490d9535120793d0e142c.zip |
am 69c04cad: Race condition in cursor move.
* commit '69c04cadc7c017f9de53f13ea045347b80316d4a':
Race condition in cursor move.
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/WordComposer.java | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 32ef1021d..8803edc88 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -232,31 +232,33 @@ public final class WordComposer { * @return true if the cursor is still inside the composing word, false otherwise. */ public boolean moveCursorByAndReturnIfInsideComposingWord(final int expectedMoveAmount) { - int actualMoveAmountWithinWord = 0; + int actualMoveAmount = 0; int cursorPos = mCursorPositionWithinWord; // TODO: Don't make that copy. We can do this directly from mTypedWordCache. final int[] codePoints = StringUtils.toCodePointArray(mTypedWordCache); if (expectedMoveAmount >= 0) { // Moving the cursor forward for the expected amount or until the end of the word has // been reached, whichever comes first. - while (actualMoveAmountWithinWord < expectedMoveAmount && cursorPos < mCodePointSize) { - actualMoveAmountWithinWord += Character.charCount(codePoints[cursorPos]); + while (actualMoveAmount < expectedMoveAmount && cursorPos < codePoints.length) { + actualMoveAmount += Character.charCount(codePoints[cursorPos]); ++cursorPos; } } else { // Moving the cursor backward for the expected amount or until the start of the word // has been reached, whichever comes first. - while (actualMoveAmountWithinWord > expectedMoveAmount && cursorPos > 0) { + while (actualMoveAmount > expectedMoveAmount && cursorPos > 0) { --cursorPos; - actualMoveAmountWithinWord -= Character.charCount(codePoints[cursorPos]); + actualMoveAmount -= Character.charCount(codePoints[cursorPos]); } } // If the actual and expected amounts differ, we crossed the start or the end of the word // so the result would not be inside the composing word. - if (actualMoveAmountWithinWord != expectedMoveAmount) return false; + if (actualMoveAmount != expectedMoveAmount) { + return false; + } mCursorPositionWithinWord = cursorPos; - mCombinerChain.applyProcessedEvent(mCombinerChain.processEvent(mEvents, - Event.createCursorMovedEvent(cursorPos))); + mCombinerChain.applyProcessedEvent(mCombinerChain.processEvent( + mEvents, Event.createCursorMovedEvent(cursorPos))); return true; } |