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
625be62a
Unverified
Commit
625be62a
authored
Apr 08, 2021
by
xubaolin
Committed by
GitHub
Apr 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix paste crash when section is invalid (#78948)
parent
2bada609
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+1
-1
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+51
-0
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
625be62a
...
...
@@ -2152,7 +2152,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
// Snapshot the input before using `await`.
// See https://github.com/flutter/flutter/issues/11427
final
ClipboardData
?
data
=
await
Clipboard
.
getData
(
Clipboard
.
kTextPlain
);
if
(
data
!=
null
)
{
if
(
data
!=
null
&&
selection
.
isValid
)
{
value
=
TextEditingValue
(
text:
selection
.
textBefore
(
text
)
+
data
.
text
!
+
selection
.
textAfter
(
text
),
selection:
TextSelection
.
collapsed
(
...
...
packages/flutter/test/material/text_field_test.dart
View file @
625be62a
...
...
@@ -4823,6 +4823,57 @@ void main() {
expect
(
find
.
text
(
expected
),
findsOneWidget
,
reason:
'Because text contains
${controller.text}
'
);
},
skip:
areKeyEventsHandledByPlatform
);
// Regressing test for https://github.com/flutter/flutter/issues/78219
testWidgets
(
'Paste does not crash when the section is inValid'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
final
TextEditingController
controller
=
TextEditingController
();
final
TextField
textField
=
TextField
(
controller:
controller
,
obscureText:
true
,
);
const
String
clipboardContent
=
'I love Flutter!'
;
SystemChannels
.
platform
.
setMockMethodCallHandler
((
MethodCall
methodCall
)
async
{
if
(
methodCall
.
method
==
'Clipboard.getData'
)
return
<
String
,
dynamic
>{
'text'
:
clipboardContent
};
return
null
;
});
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
RawKeyboardListener
(
focusNode:
focusNode
,
onKey:
null
,
child:
textField
,
),
),
),
);
focusNode
.
requestFocus
();
await
tester
.
pump
();
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
pumpAndSettle
();
// This setter will set `selection` invalid.
controller
.
text
=
''
;
// Paste clipboardContent to the text field.
await
tester
.
sendKeyDownEvent
(
LogicalKeyboardKey
.
controlRight
);
await
tester
.
sendKeyDownEvent
(
LogicalKeyboardKey
.
keyV
);
await
tester
.
pumpAndSettle
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
await
tester
.
sendKeyUpEvent
(
LogicalKeyboardKey
.
keyV
);
await
tester
.
sendKeyUpEvent
(
LogicalKeyboardKey
.
controlRight
);
await
tester
.
pumpAndSettle
();
// Do nothing.
expect
(
find
.
text
(
clipboardContent
),
findsNothing
);
expect
(
controller
.
selection
,
const
TextSelection
.
collapsed
(
offset:
-
1
));
});
testWidgets
(
'Cut test'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
final
TextEditingController
controller
=
TextEditingController
();
...
...
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