diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
4 files changed, 32 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b6d477629..38e386493 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1277,7 +1277,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Called from PointerTracker through the KeyboardActionListener interface @Override public void onTextInput(final String rawText) { - mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler); + // TODO: have the keyboard pass the correct key code when we need it. + final Event event = Event.createSoftwareTextEvent(rawText, Event.NOT_A_KEY_CODE); + mInputLogic.onTextInput(mSettings.getCurrent(), event, mHandler); mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT); } diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index 965518e34..606bb775e 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -687,13 +687,23 @@ public final class RichInputConnection { } public boolean isCursorTouchingWord(final SpacingAndPunctuations spacingAndPunctuations) { - final int codePointBeforeCursor = getCodePointBeforeCursor(); - if (Constants.NOT_A_CODE == codePointBeforeCursor - || spacingAndPunctuations.isWordSeparator(codePointBeforeCursor) - || spacingAndPunctuations.isWordConnector(codePointBeforeCursor)) { - return isCursorFollowedByWordCharacter(spacingAndPunctuations); - } - return true; + if (isCursorFollowedByWordCharacter(spacingAndPunctuations)) { + // If what's after the cursor is a word character, then we're touching a word. + return true; + } + final String textBeforeCursor = mCommittedTextBeforeComposingText.toString(); + int indexOfCodePointInJavaChars = textBeforeCursor.length(); + int consideredCodePoint = 0 == indexOfCodePointInJavaChars ? Constants.NOT_A_CODE + : textBeforeCursor.codePointBefore(indexOfCodePointInJavaChars); + // Search for the first non word-connector char + if (spacingAndPunctuations.isWordConnector(consideredCodePoint)) { + indexOfCodePointInJavaChars -= Character.charCount(consideredCodePoint); + consideredCodePoint = 0 == indexOfCodePointInJavaChars ? Constants.NOT_A_CODE + : textBeforeCursor.codePointBefore(indexOfCodePointInJavaChars); + } + return !(Constants.NOT_A_CODE == consideredCodePoint + || spacingAndPunctuations.isWordSeparator(consideredCodePoint) + || spacingAndPunctuations.isWordConnector(consideredCodePoint)); } public boolean isCursorFollowedByWordCharacter( diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 29382fea4..78990e011 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -127,6 +127,7 @@ public final class WordComposer { * Clear out the keys registered so far. */ public void reset() { + mCombinerChain.reset(); mTypedWord.setLength(0); mEvents.clear(); mAutoCorrection = null; @@ -193,7 +194,10 @@ public final class WordComposer { final int keyY = event.mY; final int newIndex = size(); mCombinerChain.processEvent(mEvents, event); - mTypedWord.appendCodePoint(primaryCode); + // TODO: remove mTypedWord and compute it dynamically when necessary. We also need to + // make the views of the composing word a SpannableString. + mTypedWord.replace(0, mTypedWord.length(), + mCombinerChain.getComposingWordWithCombiningFeedback().toString()); mEvents.add(event); refreshSize(); mCursorPositionWithinWord = mCodePointSize; @@ -243,6 +247,8 @@ public final class WordComposer { * @return true if the cursor is still inside the composing word, false otherwise. */ public boolean moveCursorByAndReturnIfInsideComposingWord(final int expectedMoveAmount) { + // TODO: should uncommit the composing feedback + mCombinerChain.reset(); int actualMoveAmountWithinWord = 0; int cursorPos = mCursorPositionWithinWord; final int[] codePoints; @@ -482,6 +488,7 @@ public final class WordComposer { mIsBatchMode = false; mPreviousWordForSuggestion = committedWord.toString(); mTypedWord.setLength(0); + mCombinerChain.reset(); mEvents.clear(); mCodePointSize = 0; mTrailingSingleQuotesCount = 0; @@ -509,6 +516,7 @@ public final class WordComposer { Collections.copy(mEvents, lastComposedWord.mEvents); mInputPointers.set(lastComposedWord.mInputPointers); mTypedWord.setLength(0); + mCombinerChain.reset(); mTypedWord.append(lastComposedWord.mTypedWord); refreshSize(); mCapitalizedMode = lastComposedWord.mCapitalizedMode; diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 8faf17584..36b30eabe 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -161,11 +161,12 @@ public final class InputLogic { * some additional keys for example. * * @param settingsValues the current values of the settings. - * @param rawText the text to input. + * @param event the input event containing the data. */ - public void onTextInput(final SettingsValues settingsValues, final String rawText, + public void onTextInput(final SettingsValues settingsValues, final Event event, // TODO: remove this argument final LatinIME.UIHandler handler) { + final String rawText = event.mText.toString(); mConnection.beginBatchEdit(); if (mWordComposer.isComposingWord()) { commitCurrentAutoCorrection(settingsValues, rawText, handler); |