@@ -1761,7 +1761,7 @@ void main() {
1761
1761
child: new TextField (
1762
1762
key: key,
1763
1763
controller: controller,
1764
- )
1764
+ ),
1765
1765
),
1766
1766
);
1767
1767
@@ -1812,6 +1812,7 @@ void main() {
1812
1812
actions: < SemanticsAction > [
1813
1813
SemanticsAction .tap,
1814
1814
SemanticsAction .moveCursorBackwardByCharacter,
1815
+ SemanticsAction .setSelection,
1815
1816
],
1816
1817
flags: < SemanticsFlag > [
1817
1818
SemanticsFlag .isTextField,
@@ -1835,6 +1836,7 @@ void main() {
1835
1836
SemanticsAction .tap,
1836
1837
SemanticsAction .moveCursorBackwardByCharacter,
1837
1838
SemanticsAction .moveCursorForwardByCharacter,
1839
+ SemanticsAction .setSelection,
1838
1840
],
1839
1841
flags: < SemanticsFlag > [
1840
1842
SemanticsFlag .isTextField,
@@ -1858,6 +1860,7 @@ void main() {
1858
1860
actions: < SemanticsAction > [
1859
1861
SemanticsAction .tap,
1860
1862
SemanticsAction .moveCursorForwardByCharacter,
1863
+ SemanticsAction .setSelection,
1861
1864
],
1862
1865
flags: < SemanticsFlag > [
1863
1866
SemanticsFlag .isTextField,
@@ -1878,10 +1881,10 @@ void main() {
1878
1881
1879
1882
await tester.pumpWidget (
1880
1883
overlay (
1881
- child: new TextField (
1882
- key: key,
1883
- controller: controller,
1884
- )
1884
+ child: new TextField (
1885
+ key: key,
1886
+ controller: controller,
1887
+ ),
1885
1888
),
1886
1889
);
1887
1890
@@ -1915,6 +1918,7 @@ void main() {
1915
1918
actions: < SemanticsAction > [
1916
1919
SemanticsAction .tap,
1917
1920
SemanticsAction .moveCursorBackwardByCharacter,
1921
+ SemanticsAction .setSelection,
1918
1922
],
1919
1923
flags: < SemanticsFlag > [
1920
1924
SemanticsFlag .isTextField,
@@ -1938,6 +1942,7 @@ void main() {
1938
1942
SemanticsAction .tap,
1939
1943
SemanticsAction .moveCursorBackwardByCharacter,
1940
1944
SemanticsAction .moveCursorForwardByCharacter,
1945
+ SemanticsAction .setSelection,
1941
1946
],
1942
1947
flags: < SemanticsFlag > [
1943
1948
SemanticsFlag .isTextField,
@@ -1950,4 +1955,94 @@ void main() {
1950
1955
semantics.dispose ();
1951
1956
});
1952
1957
1958
+ testWidgets ('TextField change selection with semantics' , (WidgetTester tester) async {
1959
+ final SemanticsTester semantics = new SemanticsTester (tester);
1960
+ final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner;
1961
+ final TextEditingController controller = new TextEditingController ()
1962
+ ..text = 'Hello' ;
1963
+ final Key key = new UniqueKey ();
1964
+
1965
+ await tester.pumpWidget (
1966
+ overlay (
1967
+ child: new TextField (
1968
+ key: key,
1969
+ controller: controller,
1970
+ ),
1971
+ ),
1972
+ );
1973
+
1974
+ // Focus the text field
1975
+ await tester.tap (find.byKey (key));
1976
+ await tester.pump ();
1977
+
1978
+ const int inputFieldId = 2 ;
1979
+
1980
+ expect (controller.selection, const TextSelection .collapsed (offset: 5 , affinity: TextAffinity .upstream));
1981
+ expect (semantics, hasSemantics (new TestSemantics .root (
1982
+ children: < TestSemantics > [
1983
+ new TestSemantics .rootChild (
1984
+ id: inputFieldId,
1985
+ value: 'Hello' ,
1986
+ textSelection: const TextSelection .collapsed (offset: 5 ),
1987
+ textDirection: TextDirection .ltr,
1988
+ actions: < SemanticsAction > [
1989
+ SemanticsAction .tap,
1990
+ SemanticsAction .moveCursorBackwardByCharacter,
1991
+ SemanticsAction .setSelection,
1992
+ ],
1993
+ flags: < SemanticsFlag > [
1994
+ SemanticsFlag .isTextField,
1995
+ SemanticsFlag .isFocused,
1996
+ ],
1997
+ ),
1998
+ ],
1999
+ ), ignoreTransform: true , ignoreRect: true ));
2000
+
2001
+ // move cursor back once
2002
+ semanticsOwner.performAction (inputFieldId, SemanticsAction .setSelection, < String , int > {
2003
+ 'base' : 4 ,
2004
+ 'extent' : 4 ,
2005
+ });
2006
+ await tester.pump ();
2007
+ expect (controller.selection, const TextSelection .collapsed (offset: 4 ));
2008
+
2009
+ // move cursor to front
2010
+ semanticsOwner.performAction (inputFieldId, SemanticsAction .setSelection, < String , int > {
2011
+ 'base' : 0 ,
2012
+ 'extent' : 0 ,
2013
+ });
2014
+ await tester.pump ();
2015
+ expect (controller.selection, const TextSelection .collapsed (offset: 0 ));
2016
+
2017
+ // select all
2018
+ semanticsOwner.performAction (inputFieldId, SemanticsAction .setSelection, < String , int > {
2019
+ 'base' : 0 ,
2020
+ 'extent' : 5 ,
2021
+ });
2022
+ await tester.pump ();
2023
+ expect (controller.selection, const TextSelection (baseOffset: 0 , extentOffset: 5 ));
2024
+ expect (semantics, hasSemantics (new TestSemantics .root (
2025
+ children: < TestSemantics > [
2026
+ new TestSemantics .rootChild (
2027
+ id: inputFieldId,
2028
+ value: 'Hello' ,
2029
+ textSelection: const TextSelection (baseOffset: 0 , extentOffset: 5 ),
2030
+ textDirection: TextDirection .ltr,
2031
+ actions: < SemanticsAction > [
2032
+ SemanticsAction .tap,
2033
+ SemanticsAction .moveCursorBackwardByCharacter,
2034
+ SemanticsAction .setSelection,
2035
+ ],
2036
+ flags: < SemanticsFlag > [
2037
+ SemanticsFlag .isTextField,
2038
+ SemanticsFlag .isFocused,
2039
+ ],
2040
+ ),
2041
+ ],
2042
+ ), ignoreTransform: true , ignoreRect: true ));
2043
+
2044
+ semantics.dispose ();
2045
+ });
2046
+
2047
+
1953
2048
}
0 commit comments