Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e204eb2f
Unverified
Commit
e204eb2f
authored
Jan 23, 2021
by
Mouad Debbar
Committed by
GitHub
Jan 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Space and arrow keys in a text field shouldn't scroll (#74454)
parent
177fd261
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
41 deletions
+130
-41
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+22
-19
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+25
-22
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+15
-0
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+33
-0
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+35
-0
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
e204eb2f
...
...
@@ -1201,25 +1201,28 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
),
);
return
Semantics
(
enabled:
enabled
,
onTap:
!
enabled
||
widget
.
readOnly
?
null
:
()
{
if
(!
controller
.
selection
.
isValid
)
{
controller
.
selection
=
TextSelection
.
collapsed
(
offset:
controller
.
text
.
length
);
}
_requestKeyboard
();
},
child:
IgnorePointer
(
ignoring:
!
enabled
,
child:
Container
(
decoration:
effectiveDecoration
,
child:
_selectionGestureDetectorBuilder
.
buildGestureDetector
(
behavior:
HitTestBehavior
.
translucent
,
child:
Align
(
alignment:
Alignment
(-
1.0
,
_textAlignVertical
.
y
),
widthFactor:
1.0
,
heightFactor:
1.0
,
child:
_addTextDependentAttachments
(
paddedEditable
,
textStyle
,
placeholderStyle
),
return
Shortcuts
(
shortcuts:
scrollShortcutOverrides
,
child:
Semantics
(
enabled:
enabled
,
onTap:
!
enabled
||
widget
.
readOnly
?
null
:
()
{
if
(!
controller
.
selection
.
isValid
)
{
controller
.
selection
=
TextSelection
.
collapsed
(
offset:
controller
.
text
.
length
);
}
_requestKeyboard
();
},
child:
IgnorePointer
(
ignoring:
!
enabled
,
child:
Container
(
decoration:
effectiveDecoration
,
child:
_selectionGestureDetectorBuilder
.
buildGestureDetector
(
behavior:
HitTestBehavior
.
translucent
,
child:
Align
(
alignment:
Alignment
(-
1.0
,
_textAlignVertical
.
y
),
widthFactor:
1.0
,
heightFactor:
1.0
,
child:
_addTextDependentAttachments
(
paddedEditable
,
textStyle
,
placeholderStyle
),
),
),
),
),
...
...
packages/flutter/lib/src/material/text_field.dart
View file @
e204eb2f
...
...
@@ -1290,29 +1290,32 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
semanticsMaxValueLength
=
null
;
}
return
MouseRegion
(
cursor:
effectiveMouseCursor
,
onEnter:
(
PointerEnterEvent
event
)
=>
_handleHover
(
true
),
onExit:
(
PointerExitEvent
event
)
=>
_handleHover
(
false
),
child:
IgnorePointer
(
ignoring:
!
_isEnabled
,
child:
AnimatedBuilder
(
animation:
controller
,
// changes the _currentLength
builder:
(
BuildContext
context
,
Widget
?
child
)
{
return
Semantics
(
maxValueLength:
semanticsMaxValueLength
,
currentValueLength:
_currentLength
,
onTap:
widget
.
readOnly
?
null
:
()
{
if
(!
_effectiveController
.
selection
.
isValid
)
_effectiveController
.
selection
=
TextSelection
.
collapsed
(
offset:
_effectiveController
.
text
.
length
);
_requestKeyboard
();
},
return
Shortcuts
(
shortcuts:
scrollShortcutOverrides
,
child:
MouseRegion
(
cursor:
effectiveMouseCursor
,
onEnter:
(
PointerEnterEvent
event
)
=>
_handleHover
(
true
),
onExit:
(
PointerExitEvent
event
)
=>
_handleHover
(
false
),
child:
IgnorePointer
(
ignoring:
!
_isEnabled
,
child:
AnimatedBuilder
(
animation:
controller
,
// changes the _currentLength
builder:
(
BuildContext
context
,
Widget
?
child
)
{
return
Semantics
(
maxValueLength:
semanticsMaxValueLength
,
currentValueLength:
_currentLength
,
onTap:
widget
.
readOnly
?
null
:
()
{
if
(!
_effectiveController
.
selection
.
isValid
)
_effectiveController
.
selection
=
TextSelection
.
collapsed
(
offset:
_effectiveController
.
text
.
length
);
_requestKeyboard
();
},
child:
child
,
);
},
child:
_selectionGestureDetectorBuilder
.
buildGestureDetector
(
behavior:
HitTestBehavior
.
translucent
,
child:
child
,
);
},
child:
_selectionGestureDetectorBuilder
.
buildGestureDetector
(
behavior:
HitTestBehavior
.
translucent
,
child:
child
,
),
),
),
),
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
e204eb2f
...
...
@@ -12,6 +12,7 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/services.dart'
;
import
'actions.dart'
;
import
'autofill.dart'
;
import
'automatic_keep_alive.dart'
;
import
'basic.dart'
;
...
...
@@ -26,6 +27,7 @@ import 'media_query.dart';
import
'scroll_controller.dart'
;
import
'scroll_physics.dart'
;
import
'scrollable.dart'
;
import
'shortcuts.dart'
;
import
'text.dart'
;
import
'text_selection.dart'
;
import
'ticker_provider.dart'
;
...
...
@@ -53,6 +55,19 @@ const Duration _kCursorBlinkWaitForStart = Duration(milliseconds: 150);
// is shown in an obscured text field.
const
int
_kObscureShowLatestCharCursorTicks
=
3
;
/// A map used to disable scrolling shortcuts in text fields.
///
/// This is a temporary fix for: https://github.com/flutter/flutter/issues/74191
final
Map
<
LogicalKeySet
,
Intent
>
scrollShortcutOverrides
=
kIsWeb
?
<
LogicalKeySet
,
Intent
>{
LogicalKeySet
(
LogicalKeyboardKey
.
space
):
DoNothingAndStopPropagationIntent
(),
LogicalKeySet
(
LogicalKeyboardKey
.
arrowUp
):
DoNothingAndStopPropagationIntent
(),
LogicalKeySet
(
LogicalKeyboardKey
.
arrowDown
):
DoNothingAndStopPropagationIntent
(),
LogicalKeySet
(
LogicalKeyboardKey
.
arrowLeft
):
DoNothingAndStopPropagationIntent
(),
LogicalKeySet
(
LogicalKeyboardKey
.
arrowRight
):
DoNothingAndStopPropagationIntent
(),
}
:
<
LogicalKeySet
,
Intent
>{};
/// A controller for an editable text field.
///
/// Whenever the user modifies a text field with an associated
...
...
packages/flutter/test/cupertino/text_field_test.dart
View file @
e204eb2f
...
...
@@ -4287,6 +4287,39 @@ void main() {
expect
(
focusNode3
.
hasPrimaryFocus
,
isTrue
);
});
testWidgets
(
'Scrolling shortcuts are disabled in text fields'
,
(
WidgetTester
tester
)
async
{
bool
scrollInvoked
=
false
;
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Actions
(
actions:
<
Type
,
Action
<
Intent
>>{
ScrollIntent:
CallbackAction
<
ScrollIntent
>(
onInvoke:
(
Intent
intent
)
{
scrollInvoked
=
true
;
}),
},
child:
ListView
(
children:
const
<
Widget
>[
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
200
)),
CupertinoTextField
(),
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
800
)),
],
),
),
),
);
await
tester
.
pump
();
expect
(
scrollInvoked
,
isFalse
);
// Set focus on the text field.
await
tester
.
tapAt
(
tester
.
getTopLeft
(
find
.
byType
(
CupertinoTextField
)));
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
space
);
expect
(
scrollInvoked
,
isFalse
);
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
arrowDown
);
expect
(
scrollInvoked
,
isFalse
);
});
testWidgets
(
'Cupertino text field semantics'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
packages/flutter/test/material/text_field_test.dart
View file @
e204eb2f
...
...
@@ -8754,6 +8754,41 @@ void main() {
expect
(
focusNode3
.
hasPrimaryFocus
,
isTrue
);
});
testWidgets
(
'Scrolling shortcuts are disabled in text fields'
,
(
WidgetTester
tester
)
async
{
bool
scrollInvoked
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Actions
(
actions:
<
Type
,
Action
<
Intent
>>{
ScrollIntent:
CallbackAction
<
ScrollIntent
>(
onInvoke:
(
Intent
intent
)
{
scrollInvoked
=
true
;
}),
},
child:
Material
(
child:
ListView
(
children:
const
<
Widget
>[
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
200
)),
TextField
(),
Padding
(
padding:
EdgeInsets
.
symmetric
(
vertical:
800
)),
],
),
),
),
),
);
await
tester
.
pump
();
expect
(
scrollInvoked
,
isFalse
);
// Set focus on the text field.
await
tester
.
tapAt
(
tester
.
getTopLeft
(
find
.
byType
(
TextField
)));
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
space
);
expect
(
scrollInvoked
,
isFalse
);
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
arrowDown
);
expect
(
scrollInvoked
,
isFalse
);
});
testWidgets
(
"A buildCounter that returns null doesn't affect the size of the TextField"
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/44909
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment