@@ -7846,17 +7846,17 @@ void main() {
7846
7846
);
7847
7847
expect (scrollController.position.pixels, 0.0 );
7848
7848
7849
- // Page Down scrolls by the height of the viewport.
7849
+ // Page Down scrolls proportionally to the height of the viewport.
7850
7850
await sendKeys (
7851
7851
tester,
7852
7852
< LogicalKeyboardKey > [
7853
7853
LogicalKeyboardKey .pageDown,
7854
7854
],
7855
7855
targetPlatform: defaultTargetPlatform,
7856
7856
);
7857
- expect (scrollController.position.pixels, lineHeight * lines);
7857
+ expect (scrollController.position.pixels, lineHeight * lines * 0.8 );
7858
7858
7859
- // Another Page Down does nothing, since it's now at the bottom.
7859
+ // Another Page Down reaches the bottom.
7860
7860
await sendKeys (
7861
7861
tester,
7862
7862
< LogicalKeyboardKey > [
@@ -7866,7 +7866,17 @@ void main() {
7866
7866
);
7867
7867
expect (scrollController.position.pixels, lineHeight * lines);
7868
7868
7869
- // Page Up now scrolls back up.
7869
+ // Page Up now scrolls back up proportionally to the height of the viewport.
7870
+ await sendKeys (
7871
+ tester,
7872
+ < LogicalKeyboardKey > [
7873
+ LogicalKeyboardKey .pageUp,
7874
+ ],
7875
+ targetPlatform: defaultTargetPlatform,
7876
+ );
7877
+ expect (scrollController.position.pixels, lineHeight * lines - lineHeight * lines * 0.8 );
7878
+
7879
+ // Another Page Up reaches the top.
7870
7880
await sendKeys (
7871
7881
tester,
7872
7882
< LogicalKeyboardKey > [
@@ -7880,6 +7890,84 @@ void main() {
7880
7890
variant: TargetPlatformVariant .all (),
7881
7891
);
7882
7892
7893
+ testWidgets ('pageup/pagedown keys in a one line field' , (WidgetTester tester) async {
7894
+ final TextEditingController controller = TextEditingController (text: testText);
7895
+ controller.selection = const TextSelection (
7896
+ baseOffset: 0 ,
7897
+ extentOffset: 0 ,
7898
+ affinity: TextAffinity .upstream,
7899
+ );
7900
+ final ScrollController scrollController = ScrollController ();
7901
+ await tester.pumpWidget (MaterialApp (
7902
+ home: Align (
7903
+ alignment: Alignment .topLeft,
7904
+ child: SizedBox (
7905
+ width: 400 ,
7906
+ child: EditableText (
7907
+ minLines: 1 ,
7908
+ controller: controller,
7909
+ scrollController: scrollController,
7910
+ showSelectionHandles: true ,
7911
+ autofocus: true ,
7912
+ focusNode: FocusNode (),
7913
+ style: Typography .material2018 ().black.subtitle1! ,
7914
+ cursorColor: Colors .blue,
7915
+ backgroundCursorColor: Colors .grey,
7916
+ selectionControls: materialTextSelectionControls,
7917
+ keyboardType: TextInputType .text,
7918
+ textAlign: TextAlign .right,
7919
+ ),
7920
+ ),
7921
+ ),
7922
+ ));
7923
+
7924
+ await tester.pump (); // Wait for autofocus to take effect.
7925
+
7926
+ expect (controller.value.selection.isCollapsed, isTrue);
7927
+ expect (controller.value.selection.baseOffset, 0 );
7928
+ expect (scrollController.position.pixels, 0.0 );
7929
+ final double lineHeight = findRenderEditable (tester).preferredLineHeight;
7930
+
7931
+ // Page Up scrolls to the end.
7932
+ await sendKeys (
7933
+ tester,
7934
+ < LogicalKeyboardKey > [
7935
+ LogicalKeyboardKey .pageUp,
7936
+ ],
7937
+ targetPlatform: defaultTargetPlatform,
7938
+ );
7939
+ expect (scrollController.position.pixels, scrollController.position.maxScrollExtent);
7940
+ expect (controller.value.selection.isCollapsed, isTrue);
7941
+ expect (controller.value.selection.baseOffset, 0 );
7942
+
7943
+ // Return scroll to the start.
7944
+ await sendKeys (
7945
+ tester,
7946
+ < LogicalKeyboardKey > [
7947
+ LogicalKeyboardKey .home,
7948
+ ],
7949
+ targetPlatform: defaultTargetPlatform,
7950
+ );
7951
+ expect (scrollController.position.pixels, 0.0 );
7952
+ expect (controller.value.selection.isCollapsed, isTrue);
7953
+ expect (controller.value.selection.baseOffset, 0 );
7954
+
7955
+ // Page Down also scrolls to the end.
7956
+ await sendKeys (
7957
+ tester,
7958
+ < LogicalKeyboardKey > [
7959
+ LogicalKeyboardKey .pageDown,
7960
+ ],
7961
+ targetPlatform: defaultTargetPlatform,
7962
+ );
7963
+ expect (scrollController.position.pixels, scrollController.position.maxScrollExtent);
7964
+ expect (controller.value.selection.isCollapsed, isTrue);
7965
+ expect (controller.value.selection.baseOffset, 0 );
7966
+ },
7967
+ skip: kIsWeb, // [intended] on web these keys are handled by the browser.
7968
+ variant: TargetPlatformVariant .all (),
7969
+ );
7970
+
7883
7971
testWidgets ('shift + pageup/pagedown keys' , (WidgetTester tester) async {
7884
7972
final TextEditingController controller = TextEditingController (text: testText);
7885
7973
controller.selection = const TextSelection (
@@ -7943,12 +8031,26 @@ void main() {
7943
8031
shift: true ,
7944
8032
targetPlatform: defaultTargetPlatform,
7945
8033
);
7946
- expect (scrollController.position.pixels, lineHeight * 1 );
8034
+ expect (scrollController.position.pixels, 0.0 );
8035
+ expect (controller.value.selection.isCollapsed, isFalse);
8036
+ expect (controller.value.selection.baseOffset, 0 );
8037
+ expect (controller.value.selection.extentOffset, 20 );
8038
+
8039
+ // Another Page Down selects further down and scrolls.
8040
+ await sendKeys (
8041
+ tester,
8042
+ < LogicalKeyboardKey > [
8043
+ LogicalKeyboardKey .pageDown,
8044
+ ],
8045
+ shift: true ,
8046
+ targetPlatform: defaultTargetPlatform,
8047
+ );
8048
+ expect (scrollController.position.pixels, 14.0 );
7947
8049
expect (controller.value.selection.isCollapsed, isFalse);
7948
8050
expect (controller.value.selection.baseOffset, 0 );
7949
- expect (controller.value.selection.extentOffset, 36 );
8051
+ expect (controller.value.selection.extentOffset, 54 );
7950
8052
7951
- // Another Page Down selects everything.
8053
+ // Another Page Down selects everything and scrolls to the bottom .
7952
8054
await sendKeys (
7953
8055
tester,
7954
8056
< LogicalKeyboardKey > [
@@ -7962,7 +8064,6 @@ void main() {
7962
8064
expect (controller.value.selection.baseOffset, 0 );
7963
8065
expect (controller.value.selection.extentOffset, controller.text.length);
7964
8066
7965
-
7966
8067
// Another Page Down does nothing, since it's now at the bottom.
7967
8068
await sendKeys (
7968
8069
tester,
@@ -8008,6 +8109,73 @@ void main() {
8008
8109
variant: TargetPlatformVariant .all (),
8009
8110
);
8010
8111
8112
+ testWidgets ('shift + pageup/pagedown keys in a one line field' , (WidgetTester tester) async {
8113
+ final TextEditingController controller = TextEditingController (text: testText);
8114
+ controller.selection = const TextSelection (
8115
+ baseOffset: 0 ,
8116
+ extentOffset: 0 ,
8117
+ affinity: TextAffinity .upstream,
8118
+ );
8119
+ final ScrollController scrollController = ScrollController ();
8120
+ await tester.pumpWidget (MaterialApp (
8121
+ home: Align (
8122
+ alignment: Alignment .topLeft,
8123
+ child: SizedBox (
8124
+ width: 400 ,
8125
+ child: EditableText (
8126
+ minLines: 1 ,
8127
+ controller: controller,
8128
+ scrollController: scrollController,
8129
+ showSelectionHandles: true ,
8130
+ autofocus: true ,
8131
+ focusNode: FocusNode (),
8132
+ style: Typography .material2018 ().black.subtitle1! ,
8133
+ cursorColor: Colors .blue,
8134
+ backgroundCursorColor: Colors .grey,
8135
+ selectionControls: materialTextSelectionControls,
8136
+ keyboardType: TextInputType .text,
8137
+ textAlign: TextAlign .right,
8138
+ ),
8139
+ ),
8140
+ ),
8141
+ ));
8142
+
8143
+ await tester.pump (); // Wait for autofocus to take effect.
8144
+
8145
+ expect (controller.value.selection.isCollapsed, isTrue);
8146
+ expect (controller.value.selection.baseOffset, 0 );
8147
+ expect (scrollController.position.pixels, 0.0 );
8148
+
8149
+ // Shift + Page Up does nothing.
8150
+ await sendKeys (
8151
+ tester,
8152
+ < LogicalKeyboardKey > [
8153
+ LogicalKeyboardKey .pageUp,
8154
+ ],
8155
+ shift: true ,
8156
+ targetPlatform: defaultTargetPlatform,
8157
+ );
8158
+ expect (scrollController.position.pixels, 0.0 );
8159
+ expect (controller.value.selection.isCollapsed, isTrue);
8160
+ expect (controller.value.selection.baseOffset, 0 );
8161
+
8162
+ // Shift + Page Down does nothing either.
8163
+ await sendKeys (
8164
+ tester,
8165
+ < LogicalKeyboardKey > [
8166
+ LogicalKeyboardKey .pageDown,
8167
+ ],
8168
+ shift: true ,
8169
+ targetPlatform: defaultTargetPlatform,
8170
+ );
8171
+ expect (scrollController.position.pixels, 0.0 );
8172
+ expect (controller.value.selection.isCollapsed, isTrue);
8173
+ expect (controller.value.selection.baseOffset, 0 );
8174
+ },
8175
+ skip: kIsWeb, // [intended] on web these keys are handled by the browser.
8176
+ variant: TargetPlatformVariant .all (),
8177
+ );
8178
+
8011
8179
// Regression test for https://github.com/flutter/flutter/issues/31287
8012
8180
testWidgets ('text selection handle visibility' , (WidgetTester tester) async {
8013
8181
// Text with two separate words to select.
0 commit comments