Bug 1438682 - 1. Cache initial selection offsets; r?esawin
Getting the selection offsets in onCreateInputConnection can fail
because of us being on a wrong thread. The solution is to cache the last
selection offsets and use those in onCreateInputConnection.
MozReview-Commit-ID: AOlZsuOvzHm
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -62,16 +62,18 @@ import android.view.inputmethod.InputMet
// Managed only by notifyIMEContext; see comments in notifyIMEContext
private int mIMEState;
private String mIMETypeHint = "";
private String mIMEModeHint = "";
private String mIMEActionHint = "";
private int mIMEFlags;
private boolean mFocused;
+ private int mLastSelectionStart;
+ private int mLastSelectionEnd;
private String mCurrentInputMethod = "";
private final GeckoSession mSession;
private final View mView;
private final TextInputController.EditableClient mEditableClient;
protected int mBatchEditCount;
private ExtractedTextRequest mUpdateRequest;
@@ -334,18 +336,19 @@ import android.view.inputmethod.InputMet
imm.updateExtractedText(v, mUpdateRequest.token, mUpdateExtract);
}
@Override // TextInputController.EditableListener
public void onSelectionChange() {
final Editable editable = getEditable();
if (editable != null) {
- notifySelectionChange(Selection.getSelectionStart(editable),
- Selection.getSelectionEnd(editable));
+ mLastSelectionStart = Selection.getSelectionStart(editable);
+ mLastSelectionEnd = Selection.getSelectionEnd(editable);
+ notifySelectionChange(mLastSelectionStart, mLastSelectionEnd);
}
}
private void notifySelectionChange(int start, int end) {
final InputMethodManager imm = getInputMethodManager();
final View v = getView();
final Editable editable = getEditable();
@@ -635,19 +638,18 @@ import android.view.inputmethod.InputMet
}
String prevInputMethod = mCurrentInputMethod;
mCurrentInputMethod = InputMethods.getCurrentInputMethod(context);
if (DEBUG) {
Log.d(LOGTAG, "IME: CurrentInputMethod=" + mCurrentInputMethod);
}
- Editable editable = getEditable();
- outAttrs.initialSelStart = Selection.getSelectionStart(editable);
- outAttrs.initialSelEnd = Selection.getSelectionEnd(editable);
+ outAttrs.initialSelStart = mLastSelectionStart;
+ outAttrs.initialSelEnd = mLastSelectionEnd;
if ((mIMEFlags & IME_FLAG_USER_ACTION) != 0) {
if ((context instanceof Activity) &&
ActivityUtils.isFullScreen((Activity) context)) {
showSoftInputWithToolbar(false);
} else {
showSoftInputWithToolbar(true);
}