diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 15ddcf9ae..8831d36f7 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -119,17 +119,10 @@ public final class InputLogic { * Initializes the input logic for input in an editor. * * Call this when input starts or restarts in some editor (typically, in onStartInputView). - * If the input is starting in the same field as before, set `restarting' to true. This allows - * the input logic to reset only necessary stuff and save performance. Also, when restarting - * some things must not be done (for example, the keyboard should not be reset to the - * alphabetic layout), so do not send false to this just in case. * - * @param restarting whether input is starting in the same field as before. Unused for now. - * @param editorInfo the editorInfo associated with the editor. * @param combiningSpec the combining spec string for this subtype */ - public void startInput(final boolean restarting, final EditorInfo editorInfo, - final String combiningSpec) { + public void startInput(final String combiningSpec) { mEnteredText = null; mWordComposer.restartCombining(combiningSpec); resetComposingState(true /* alsoResetLastComposedWord */); @@ -154,7 +147,8 @@ public final class InputLogic { * @param combiningSpec the spec string for the combining rules */ public void onSubtypeChanged(final String combiningSpec) { - mWordComposer.restartCombining(combiningSpec); + finishInput(); + startInput(combiningSpec); } /** @@ -187,11 +181,16 @@ public final class InputLogic { * * @param settingsValues the current values of the settings. * @param event the input event containing the data. + * @return the complete transaction object */ - public void onTextInput(final SettingsValues settingsValues, final Event event, + public InputTransaction onTextInput(final SettingsValues settingsValues, final Event event, + final int keyboardShiftMode, // TODO: remove this argument final LatinIME.UIHandler handler) { final String rawText = event.mText.toString(); + final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, + SystemClock.uptimeMillis(), mSpaceState, + getActualCapsMode(settingsValues, keyboardShiftMode)); mConnection.beginBatchEdit(); if (mWordComposer.isComposingWord()) { commitCurrentAutoCorrection(settingsValues, rawText, handler); @@ -208,12 +207,14 @@ public final class InputLogic { // Space state must be updated before calling updateShiftState mSpaceState = SpaceState.NONE; mEnteredText = text; + inputTransaction.setDidAffectContents(); + inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); + return inputTransaction; } /** * A suggestion was picked from the suggestion strip. * @param settingsValues the current values of the settings. - * @param index the index of the suggestion. * @param suggestionInfo the suggestion info. * @param keyboardShiftState the shift state of the keyboard, as returned by * {@link com.android.inputmethod.keyboard.KeyboardSwitcher#getKeyboardShiftMode()} @@ -222,9 +223,9 @@ public final class InputLogic { // Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener} // interface public InputTransaction onPickSuggestionManually(final SettingsValues settingsValues, - final int index, final SuggestedWordInfo suggestionInfo, final int keyboardShiftState, - // TODO: remove this argument - final LatinIME.UIHandler handler) { + final SuggestedWordInfo suggestionInfo, final int keyboardShiftState, + // TODO: remove these arguments + final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { final SuggestedWords suggestedWords = mSuggestedWords; final String suggestion = suggestionInfo.mWord; // If this is a punctuation picked from the suggestion strip, pass it to onCodeInput @@ -232,12 +233,16 @@ public final class InputLogic { // Word separators are suggested before the user inputs something. // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. final Event event = Event.createPunctuationSuggestionPickedEvent(suggestionInfo); - return onCodeInput(settingsValues, event, keyboardShiftState, handler); + return onCodeInput(settingsValues, event, keyboardShiftState, + currentKeyboardScriptId, handler); } final Event event = Event.createSuggestionPickedEvent(suggestionInfo); final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, SystemClock.uptimeMillis(), mSpaceState, keyboardShiftState); + // Manual pick affects the contents of the editor, so we take note of this. It's important + // for the sequence of language switching. + inputTransaction.setDidAffectContents(); mConnection.beginBatchEdit(); if (SpaceState.PHANTOM == mSpaceState && suggestion.length() > 0 // In the batch input mode, a manually picked suggested word should just replace @@ -378,8 +383,8 @@ public final class InputLogic { */ public InputTransaction onCodeInput(final SettingsValues settingsValues, final Event event, final int keyboardShiftMode, - // TODO: remove this argument - final LatinIME.UIHandler handler) { + // TODO: remove these arguments + final int currentKeyboardScriptId, final LatinIME.UIHandler handler) { final InputTransaction inputTransaction = new InputTransaction(settingsValues, event, SystemClock.uptimeMillis(), mSpaceState, getActualCapsMode(settingsValues, keyboardShiftMode)); @@ -403,7 +408,9 @@ public final class InputLogic { // A special key, like delete, shift, emoji, or the settings key. switch (event.mKeyCode) { case Constants.CODE_DELETE: - handleBackspace(inputTransaction); + handleBackspace(inputTransaction, currentKeyboardScriptId); + // Backspace is a functional key, but it affects the contents of the editor. + inputTransaction.setDidAffectContents(); break; case Constants.CODE_SHIFT: performRecapitalization(inputTransaction.mSettingsValues); @@ -457,11 +464,15 @@ public final class InputLogic { inputTransaction.mTimestamp, inputTransaction.mSpaceState, inputTransaction.mShiftState); didAutoCorrect = handleNonSpecialCharacter(tmpTransaction, handler); + // Shift + Enter is treated as a functional key but it results in adding a new + // line, so that does affect the contents of the editor. + inputTransaction.setDidAffectContents(); break; default: throw new RuntimeException("Unknown key code : " + event.mKeyCode); } } else { + inputTransaction.setDidAffectContents(); switch (event.mCodePoint) { case Constants.CODE_ENTER: final EditorInfo editorInfo = getCurrentInputEditorInfo(); @@ -857,7 +868,9 @@ public final class InputLogic { * Handle a press on the backspace key. * @param inputTransaction The transaction in progress. */ - private void handleBackspace(final InputTransaction inputTransaction) { + private void handleBackspace(final InputTransaction inputTransaction, + // TODO: remove this argument, put it into settingsValues + final int currentKeyboardScriptId) { mSpaceState = SpaceState.NONE; mDeleteCount++; @@ -991,7 +1004,7 @@ public final class InputLogic { && !mConnection.isCursorFollowedByWordCharacter( inputTransaction.mSettingsValues.mSpacingAndPunctuations)) { restartSuggestionsOnWordTouchedByCursor(inputTransaction.mSettingsValues, - true /* shouldIncludeResumedWordInSuggestions */); + true /* shouldIncludeResumedWordInSuggestions */, currentKeyboardScriptId); } } } @@ -1244,7 +1257,9 @@ public final class InputLogic { */ // TODO: make this private. public void restartSuggestionsOnWordTouchedByCursor(final SettingsValues settingsValues, - final boolean shouldIncludeResumedWordInSuggestions) { + final boolean shouldIncludeResumedWordInSuggestions, + // TODO: remove this argument, put it into settingsValues + final int currentKeyboardScriptId) { // HACK: We may want to special-case some apps that exhibit bad behavior in case of // recorrection. This is a temporary, stopgap measure that will be removed later. // TODO: remove this. |