Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 81f219c

Browse files
[Android Text Input] Make the editing state listenable and allow batch edits (#21534)
1 parent 3de2432 commit 81f219c

File tree

11 files changed

+1688
-416
lines changed

11 files changed

+1688
-416
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/StringCod
809809
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/FlutterTextUtils.java
810810
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/ImeSyncDeferringInsetsCallback.java
811811
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java
812+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/ListenableEditingState.java
812813
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java
813814
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/localization/LocalizationPlugin.java
814815
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/mouse/MouseCursorPlugin.java

shell/platform/android/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ android_java_sources = [
217217
"io/flutter/plugin/editing/FlutterTextUtils.java",
218218
"io/flutter/plugin/editing/ImeSyncDeferringInsetsCallback.java",
219219
"io/flutter/plugin/editing/InputConnectionAdaptor.java",
220+
"io/flutter/plugin/editing/ListenableEditingState.java",
220221
"io/flutter/plugin/editing/TextInputPlugin.java",
221222
"io/flutter/plugin/localization/LocalizationPlugin.java",
222223
"io/flutter/plugin/mouse/MouseCursorPlugin.java",
@@ -473,6 +474,7 @@ action("robolectric_tests") {
473474
"test/io/flutter/plugin/common/StandardMessageCodecTest.java",
474475
"test/io/flutter/plugin/common/StandardMethodCodecTest.java",
475476
"test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java",
477+
"test/io/flutter/plugin/editing/ListenableEditingStateTest.java",
476478
"test/io/flutter/plugin/editing/TextInputPluginTest.java",
477479
"test/io/flutter/plugin/localization/LocalizationPluginTest.java",
478480
"test/io/flutter/plugin/mouse/MouseCursorPluginTest.java",

shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,60 @@ public static TextEditState fromJson(@NonNull JSONObject textEditState) throws J
675675
return new TextEditState(
676676
textEditState.getString("text"),
677677
textEditState.getInt("selectionBase"),
678-
textEditState.getInt("selectionExtent"));
678+
textEditState.getInt("selectionExtent"),
679+
textEditState.getInt("composingBase"),
680+
textEditState.getInt("composingExtent"));
679681
}
680682

681683
@NonNull public final String text;
682684
public final int selectionStart;
683685
public final int selectionEnd;
686+
public final int composingStart;
687+
public final int composingEnd;
688+
689+
public TextEditState(
690+
@NonNull String text,
691+
int selectionStart,
692+
int selectionEnd,
693+
int composingStart,
694+
int composingEnd)
695+
throws IndexOutOfBoundsException {
696+
697+
if ((selectionStart != -1 || selectionEnd != -1)
698+
&& (selectionStart < 0 || selectionStart > selectionEnd)) {
699+
throw new IndexOutOfBoundsException(
700+
"invalid selection: ("
701+
+ String.valueOf(selectionStart)
702+
+ ", "
703+
+ String.valueOf(selectionEnd)
704+
+ ")");
705+
}
706+
707+
if ((composingStart != -1 || composingEnd != -1)
708+
&& (composingStart < 0 || composingStart >= composingEnd)) {
709+
throw new IndexOutOfBoundsException(
710+
"invalid composing range: ("
711+
+ String.valueOf(composingStart)
712+
+ ", "
713+
+ String.valueOf(composingEnd)
714+
+ ")");
715+
}
716+
717+
if (composingStart > text.length()) {
718+
throw new IndexOutOfBoundsException(
719+
"invalid composing start: " + String.valueOf(composingStart));
720+
}
721+
722+
if (selectionStart > text.length()) {
723+
throw new IndexOutOfBoundsException(
724+
"invalid selection start: " + String.valueOf(selectionStart));
725+
}
684726

685-
public TextEditState(@NonNull String text, int selectionStart, int selectionEnd) {
686727
this.text = text;
687728
this.selectionStart = selectionStart;
688729
this.selectionEnd = selectionEnd;
730+
this.composingStart = composingStart;
731+
this.composingEnd = composingEnd;
689732
}
690733
}
691734
}

0 commit comments

Comments
 (0)