Fixing bug when ListenableEditingState is provided initialState with a valid composing range, android.view.inputmethod.BaseInputConnection.setComposingRegion(int, int) has NPE (flutter/engine#30916)

This commit is contained in:
fzyzcjy
2022-01-21 05:10:12 +08:00
committed by GitHub
parent 5efc2ba8d0
commit 37cc235a2b
2 changed files with 12 additions and 3 deletions

View File

@@ -60,9 +60,6 @@ class ListenableEditingState extends SpannableStringBuilder {
public ListenableEditingState(
@Nullable TextInputChannel.TextEditState initialState, @NonNull View view) {
super();
if (initialState != null) {
setEditingState(initialState);
}
Editable self = this;
mDummyConnection =
@@ -72,6 +69,10 @@ class ListenableEditingState extends SpannableStringBuilder {
return self;
}
};
if (initialState != null) {
setEditingState(initialState);
}
}
public ArrayList<TextEditingDelta> extractBatchTextEditingDeltas() {

View File

@@ -42,6 +42,14 @@ public class ListenableEditingStateTest {
MockitoAnnotations.openMocks(this);
}
@Test
public void testConstructor() {
// When provided valid composing range, should not fail
new ListenableEditingState(
new TextInputChannel.TextEditState("hello", 1, 4, 1, 4),
new View(RuntimeEnvironment.application));
}
// -------- Start: Test BatchEditing -------
@Test
public void testBatchEditing() {