Merge "Fix a bug where the caps mode would not be changed"
This commit is contained in:
commit
29eeef75ec
3 changed files with 46 additions and 22 deletions
|
@ -144,7 +144,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
||||||
private WordComposer mWordComposer = new WordComposer();
|
private WordComposer mWordComposer = new WordComposer();
|
||||||
private RichInputConnection mConnection = new RichInputConnection();
|
private RichInputConnection mConnection = new RichInputConnection(this);
|
||||||
|
|
||||||
// Keep track of the last selection range to decide if we need to show word alternatives
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
||||||
private static final int NOT_A_CURSOR_POSITION = -1;
|
private static final int NOT_A_CURSOR_POSITION = -1;
|
||||||
|
@ -537,7 +537,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
if (mDisplayOrientation != conf.orientation) {
|
if (mDisplayOrientation != conf.orientation) {
|
||||||
mDisplayOrientation = conf.orientation;
|
mDisplayOrientation = conf.orientation;
|
||||||
mHandler.startOrientationChanging();
|
mHandler.startOrientationChanging();
|
||||||
mConnection.beginBatchEdit(getCurrentInputConnection());
|
mConnection.beginBatchEdit();
|
||||||
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
||||||
mConnection.finishComposingText();
|
mConnection.finishComposingText();
|
||||||
mConnection.endBatchEdit();
|
mConnection.endBatchEdit();
|
||||||
|
@ -1213,7 +1213,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
}
|
}
|
||||||
mLastKeyTime = when;
|
mLastKeyTime = when;
|
||||||
mConnection.beginBatchEdit(getCurrentInputConnection());
|
mConnection.beginBatchEdit();
|
||||||
|
|
||||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||||
ResearchLogger.latinIME_onCodeInput(primaryCode, x, y);
|
ResearchLogger.latinIME_onCodeInput(primaryCode, x, y);
|
||||||
|
@ -1298,7 +1298,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextInput(CharSequence text) {
|
public void onTextInput(CharSequence text) {
|
||||||
mConnection.beginBatchEdit(getCurrentInputConnection());
|
mConnection.beginBatchEdit();
|
||||||
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
||||||
text = specificTldProcessingOnTextInput(text);
|
text = specificTldProcessingOnTextInput(text);
|
||||||
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
||||||
|
@ -1819,7 +1819,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mKeyboardSwitcher.updateShiftState();
|
mKeyboardSwitcher.updateShiftState();
|
||||||
resetComposingState(true /* alsoResetLastComposedWord */);
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||||
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
||||||
mConnection.beginBatchEdit(getCurrentInputConnection());
|
mConnection.beginBatchEdit();
|
||||||
mConnection.commitCompletion(completionInfo);
|
mConnection.commitCompletion(completionInfo);
|
||||||
mConnection.endBatchEdit();
|
mConnection.endBatchEdit();
|
||||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
@ -41,16 +42,18 @@ public class RichInputConnection {
|
||||||
private static final Pattern spaceRegex = Pattern.compile("\\s+");
|
private static final Pattern spaceRegex = Pattern.compile("\\s+");
|
||||||
private static final int INVALID_CURSOR_POSITION = -1;
|
private static final int INVALID_CURSOR_POSITION = -1;
|
||||||
|
|
||||||
|
private final InputMethodService mParent;
|
||||||
InputConnection mIC;
|
InputConnection mIC;
|
||||||
int mNestLevel;
|
int mNestLevel;
|
||||||
public RichInputConnection() {
|
public RichInputConnection(final InputMethodService parent) {
|
||||||
|
mParent = parent;
|
||||||
mIC = null;
|
mIC = null;
|
||||||
mNestLevel = 0;
|
mNestLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginBatchEdit(final InputConnection newInputConnection) {
|
public void beginBatchEdit() {
|
||||||
if (++mNestLevel == 1) {
|
if (++mNestLevel == 1) {
|
||||||
mIC = newInputConnection;
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null != mIC) mIC.beginBatchEdit();
|
if (null != mIC) mIC.beginBatchEdit();
|
||||||
} else {
|
} else {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
|
@ -84,16 +87,19 @@ public class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCursorCapsMode(final int inputType) {
|
public int getCursorCapsMode(final int inputType) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF;
|
if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF;
|
||||||
return mIC.getCursorCapsMode(inputType);
|
return mIC.getCursorCapsMode(inputType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getTextBeforeCursor(final int i, final int j) {
|
public CharSequence getTextBeforeCursor(final int i, final int j) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null != mIC) return mIC.getTextBeforeCursor(i, j);
|
if (null != mIC) return mIC.getTextBeforeCursor(i, j);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getTextAfterCursor(final int i, final int j) {
|
public CharSequence getTextAfterCursor(final int i, final int j) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null != mIC) return mIC.getTextAfterCursor(i, j);
|
if (null != mIC) return mIC.getTextAfterCursor(i, j);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +110,7 @@ public class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performEditorAction(final int actionId) {
|
public void performEditorAction(final int actionId) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null != mIC) mIC.performEditorAction(actionId);
|
if (null != mIC) mIC.performEditorAction(actionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +140,7 @@ public class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getPreviousWord(final String sentenceSeperators) {
|
public CharSequence getPreviousWord(final String sentenceSeperators) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
//TODO: Should fix this. This could be slow!
|
//TODO: Should fix this. This could be slow!
|
||||||
if (null == mIC) return null;
|
if (null == mIC) return null;
|
||||||
CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
||||||
|
@ -194,6 +202,7 @@ public class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharSequence getThisWord(String sentenceSeperators) {
|
public CharSequence getThisWord(String sentenceSeperators) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null == mIC) return null;
|
if (null == mIC) return null;
|
||||||
final CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
final CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
||||||
return getThisWord(prev, sentenceSeperators);
|
return getThisWord(prev, sentenceSeperators);
|
||||||
|
@ -233,6 +242,7 @@ public class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCursorPosition() {
|
private int getCursorPosition() {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null == mIC) return INVALID_CURSOR_POSITION;
|
if (null == mIC) return INVALID_CURSOR_POSITION;
|
||||||
final ExtractedText extracted = mIC.getExtractedText(new ExtractedTextRequest(), 0);
|
final ExtractedText extracted = mIC.getExtractedText(new ExtractedTextRequest(), 0);
|
||||||
if (extracted == null) {
|
if (extracted == null) {
|
||||||
|
@ -250,6 +260,7 @@ public class RichInputConnection {
|
||||||
* @return a range containing the text surrounding the cursor
|
* @return a range containing the text surrounding the cursor
|
||||||
*/
|
*/
|
||||||
public Range getWordRangeAtCursor(String sep, int additionalPrecedingWordsCount) {
|
public Range getWordRangeAtCursor(String sep, int additionalPrecedingWordsCount) {
|
||||||
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (mIC == null || sep == null) {
|
if (mIC == null || sep == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.view.inputmethod.ExtractedText;
|
import android.view.inputmethod.ExtractedText;
|
||||||
import android.view.inputmethod.ExtractedTextRequest;
|
import android.view.inputmethod.ExtractedTextRequest;
|
||||||
|
@ -83,6 +84,17 @@ public class RichInputConnectionTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MockInputMethodService extends InputMethodService {
|
||||||
|
InputConnection mInputConnection;
|
||||||
|
public void setInputConnection(final InputConnection inputConnection) {
|
||||||
|
mInputConnection = inputConnection;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public InputConnection getCurrentInputConnection() {
|
||||||
|
return mInputConnection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/************************** Tests ************************/
|
/************************** Tests ************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,14 +134,14 @@ public class RichInputConnectionTests extends AndroidTestCase {
|
||||||
*/
|
*/
|
||||||
public void testGetWordRangeAtCursor() {
|
public void testGetWordRangeAtCursor() {
|
||||||
ExtractedText et = new ExtractedText();
|
ExtractedText et = new ExtractedText();
|
||||||
final RichInputConnection ic = new RichInputConnection();
|
final MockInputMethodService mockInputMethodService = new MockInputMethodService();
|
||||||
InputConnection mockConnection;
|
final RichInputConnection ic = new RichInputConnection(mockInputMethodService);
|
||||||
mockConnection = new MockConnection("word wo", "rd", et);
|
mockInputMethodService.setInputConnection(new MockConnection("word wo", "rd", et));
|
||||||
et.startOffset = 0;
|
et.startOffset = 0;
|
||||||
et.selectionStart = 7;
|
et.selectionStart = 7;
|
||||||
Range r;
|
Range r;
|
||||||
|
|
||||||
ic.beginBatchEdit(mockConnection);
|
ic.beginBatchEdit();
|
||||||
// basic case
|
// basic case
|
||||||
r = ic.getWordRangeAtCursor(" ", 0);
|
r = ic.getWordRangeAtCursor(" ", 0);
|
||||||
assertEquals("word", r.mWord);
|
assertEquals("word", r.mWord);
|
||||||
|
@ -140,37 +152,38 @@ public class RichInputConnectionTests extends AndroidTestCase {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
|
|
||||||
// tab character instead of space
|
// tab character instead of space
|
||||||
mockConnection = new MockConnection("one\tword\two", "rd", et);
|
mockInputMethodService.setInputConnection(new MockConnection("one\tword\two", "rd", et));
|
||||||
ic.beginBatchEdit(mockConnection);
|
ic.beginBatchEdit();
|
||||||
r = ic.getWordRangeAtCursor("\t", 1);
|
r = ic.getWordRangeAtCursor("\t", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
assertEquals("word\tword", r.mWord);
|
assertEquals("word\tword", r.mWord);
|
||||||
|
|
||||||
// only one word doesn't go too far
|
// only one word doesn't go too far
|
||||||
mockConnection = new MockConnection("one\tword\two", "rd", et);
|
mockInputMethodService.setInputConnection(new MockConnection("one\tword\two", "rd", et));
|
||||||
ic.beginBatchEdit(mockConnection);
|
ic.beginBatchEdit();
|
||||||
r = ic.getWordRangeAtCursor("\t", 1);
|
r = ic.getWordRangeAtCursor("\t", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
assertEquals("word\tword", r.mWord);
|
assertEquals("word\tword", r.mWord);
|
||||||
|
|
||||||
// tab or space
|
// tab or space
|
||||||
mockConnection = new MockConnection("one word\two", "rd", et);
|
mockInputMethodService.setInputConnection(new MockConnection("one word\two", "rd", et));
|
||||||
ic.beginBatchEdit(mockConnection);
|
ic.beginBatchEdit();
|
||||||
r = ic.getWordRangeAtCursor(" \t", 1);
|
r = ic.getWordRangeAtCursor(" \t", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
assertEquals("word\tword", r.mWord);
|
assertEquals("word\tword", r.mWord);
|
||||||
|
|
||||||
// tab or space multiword
|
// tab or space multiword
|
||||||
mockConnection = new MockConnection("one word\two", "rd", et);
|
mockInputMethodService.setInputConnection(new MockConnection("one word\two", "rd", et));
|
||||||
ic.beginBatchEdit(mockConnection);
|
ic.beginBatchEdit();
|
||||||
r = ic.getWordRangeAtCursor(" \t", 2);
|
r = ic.getWordRangeAtCursor(" \t", 2);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
assertEquals("one word\tword", r.mWord);
|
assertEquals("one word\tword", r.mWord);
|
||||||
|
|
||||||
// splitting on supplementary character
|
// splitting on supplementary character
|
||||||
final String supplementaryChar = "\uD840\uDC8A";
|
final String supplementaryChar = "\uD840\uDC8A";
|
||||||
mockConnection = new MockConnection("one word" + supplementaryChar + "wo", "rd", et);
|
mockInputMethodService.setInputConnection(
|
||||||
ic.beginBatchEdit(mockConnection);
|
new MockConnection("one word" + supplementaryChar + "wo", "rd", et));
|
||||||
|
ic.beginBatchEdit();
|
||||||
r = ic.getWordRangeAtCursor(supplementaryChar, 0);
|
r = ic.getWordRangeAtCursor(supplementaryChar, 0);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
assertEquals("word", r.mWord);
|
assertEquals("word", r.mWord);
|
||||||
|
|
Loading…
Reference in a new issue