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
533a5dde
Unverified
Commit
533a5dde
authored
Feb 24, 2022
by
Tomasz Gucio
Committed by
GitHub
Feb 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call bringIntoView after RenderEditable updates on paste (#98604)
parent
edc16121
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
7 deletions
+67
-7
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+21
-5
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+46
-2
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
533a5dde
...
...
@@ -1689,7 +1689,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
Clipboard
.
setData
(
ClipboardData
(
text:
selection
.
textInside
(
text
)));
_replaceText
(
ReplaceTextIntent
(
textEditingValue
,
''
,
selection
,
cause
));
if
(
cause
==
SelectionChangedCause
.
toolbar
)
{
bringIntoView
(
textEditingValue
.
selection
.
extent
);
// Schedule a call to bringIntoView() after renderEditable updates.
SchedulerBinding
.
instance
.
addPostFrameCallback
((
_
)
{
bringIntoView
(
textEditingValue
.
selection
.
extent
);
});
hideToolbar
();
}
_clipboardStatus
?.
update
();
...
...
@@ -1715,7 +1718,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_replaceText
(
ReplaceTextIntent
(
textEditingValue
,
data
.
text
!,
selection
,
cause
));
if
(
cause
==
SelectionChangedCause
.
toolbar
)
{
bringIntoView
(
textEditingValue
.
selection
.
extent
);
// Schedule a call to bringIntoView() after renderEditable updates.
SchedulerBinding
.
instance
.
addPostFrameCallback
((
_
)
{
bringIntoView
(
textEditingValue
.
selection
.
extent
);
});
hideToolbar
();
}
}
...
...
@@ -3095,10 +3101,20 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
}
void
_replaceText
(
ReplaceTextIntent
intent
)
{
userUpdateTextEditingValue
(
intent
.
currentTextEditingValue
.
replaced
(
intent
.
replacementRange
,
intent
.
replacementText
),
intent
.
cause
,
final
TextEditingValue
oldValue
=
_value
;
final
TextEditingValue
newValue
=
intent
.
currentTextEditingValue
.
replaced
(
intent
.
replacementRange
,
intent
.
replacementText
,
);
userUpdateTextEditingValue
(
newValue
,
intent
.
cause
);
// If there's no change in text and selection (e.g. when selecting and
// pasting identical text), the widget won't be rebuilt on value update.
// Handle this by calling _didChangeTextEditingValue() so caret and scroll
// updates can happen.
if
(
newValue
==
oldValue
)
{
_didChangeTextEditingValue
();
}
}
late
final
Action
<
ReplaceTextIntent
>
_replaceTextAction
=
CallbackAction
<
ReplaceTextIntent
>(
onInvoke:
_replaceText
);
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
533a5dde
...
...
@@ -10948,12 +10948,12 @@ void main() {
// Paste
await
resetSelectionAndScrollOffset
();
textSelectionDelegate
.
pasteText
(
SelectionChangedCause
.
keyboard
);
await
textSelectionDelegate
.
pasteText
(
SelectionChangedCause
.
keyboard
);
await
tester
.
pump
();
expect
(
scrollController
.
offset
,
maxScrollExtent
);
await
resetSelectionAndScrollOffset
();
textSelectionDelegate
.
pasteText
(
SelectionChangedCause
.
toolbar
);
await
textSelectionDelegate
.
pasteText
(
SelectionChangedCause
.
toolbar
);
await
tester
.
pump
();
expect
(
scrollController
.
offset
.
roundToDouble
(),
0.0
);
...
...
@@ -10980,6 +10980,50 @@ void main() {
expect
(
scrollController
.
offset
.
roundToDouble
(),
0.0
);
});
testWidgets
(
'Should not scroll on paste if caret already visible'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/96658.
final
ScrollController
scrollController
=
ScrollController
();
final
TextEditingController
controller
=
TextEditingController
(
text:
'Lorem ipsum please paste here:
\n
${".\n" * 50}
'
,
);
final
FocusNode
focusNode
=
FocusNode
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Center
(
child:
SizedBox
(
height:
600.0
,
width:
600.0
,
child:
EditableText
(
controller:
controller
,
scrollController:
scrollController
,
focusNode:
focusNode
,
maxLines:
null
,
style:
const
TextStyle
(
fontSize:
36.0
),
backgroundCursorColor:
Colors
.
grey
,
cursorColor:
cursorColor
,
),
),
),
)
);
await
Clipboard
.
setData
(
const
ClipboardData
(
text:
'Fairly long text to be pasted'
));
focusNode
.
requestFocus
();
final
EditableTextState
state
=
tester
.
state
<
EditableTextState
>(
find
.
byType
(
EditableText
));
expect
(
scrollController
.
offset
,
0.0
);
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
31
);
await
state
.
pasteText
(
SelectionChangedCause
.
toolbar
);
await
tester
.
pumpAndSettle
();
// No scroll should happen as the caret is in the viewport all the time.
expect
(
scrollController
.
offset
,
0.0
);
});
testWidgets
(
'Autofill enabled by default'
,
(
WidgetTester
tester
)
async
{
final
FocusNode
focusNode
=
FocusNode
();
await
tester
.
pumpWidget
(
...
...
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