Fix textfield input chinese error with specific IME on Android.

This commit is contained in:
Vincent Yang 2015-10-09 12:06:22 +08:00
parent cdf6fa8a54
commit 90ef4be103
1 changed files with 18 additions and 9 deletions

View File

@ -79,17 +79,26 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
if (this.isFullScreenEdit()) { if (this.isFullScreenEdit()) {
return; return;
} }
int old_i = 0;
int new_i = 0;
while (old_i < this.mText.length() && new_i < s.length()) {
if (this.mText.charAt(old_i) != s.charAt(new_i)) {
break;
}
old_i += 1;
new_i += 1;
}
int nModified = s.length() - this.mText.length(); for (; old_i < this.mText.length(); ++old_i) {
if (nModified > 0) {
final String insertText = s.subSequence(this.mText.length(), s.length()).toString();
this.mCocos2dxGLSurfaceView.insertText(insertText);
} else if(nModified < 0) {
for (; nModified < 0; ++nModified) {
this.mCocos2dxGLSurfaceView.deleteBackward(); this.mCocos2dxGLSurfaceView.deleteBackward();
} }
int nModified = s.length() - new_i;
if (nModified > 0) {
final String insertText = s.subSequence(new_i, s.length()).toString();
this.mCocos2dxGLSurfaceView.insertText(insertText);
} }
this.mText = s.toString(); this.mText = s.toString();
} }