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
82735b89
Unverified
Commit
82735b89
authored
Nov 30, 2021
by
LongCatIsLooong
Committed by
GitHub
Nov 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Fix scroll offset when caret larger than viewport (#93248)" (#94386)
This reverts commit
1e255b13
.
parent
fc60e669
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
103 deletions
+5
-103
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+2
-2
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+3
-101
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
82735b89
...
...
@@ -2151,7 +2151,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if
(!
_isMultiline
)
{
additionalOffset
=
rect
.
width
>=
editableSize
.
width
// Center `rect` if it's oversized.
?
rect
.
center
.
dx
-
editableSize
.
width
/
2
?
editableSize
.
width
/
2
-
rect
.
center
.
dx
// Valid additional offsets range from (rect.right - size.width)
// to (rect.left). Pick the closest one if out of range.
:
0.0
.
clamp
(
rect
.
right
-
editableSize
.
width
,
rect
.
left
);
...
...
@@ -2167,7 +2167,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
);
additionalOffset
=
expandedRect
.
height
>=
editableSize
.
height
?
e
xpandedRect
.
center
.
dy
-
editableSize
.
height
/
2
?
e
ditableSize
.
height
/
2
-
expandedRect
.
center
.
dy
:
0.0
.
clamp
(
expandedRect
.
bottom
-
editableSize
.
height
,
expandedRect
.
top
);
unitOffset
=
const
Offset
(
0
,
1
);
}
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
82735b89
...
...
@@ -6077,111 +6077,12 @@ void main() {
state
.
bringIntoView
(
TextPosition
(
offset:
controller
.
text
.
length
));
await
tester
.
pumpAndSettle
();
// The SingleChildScrollView is scrolled instead of the EditableText to reveal the caret.
// The SingleChildScrollView is scrolled instead of the EditableText to
// reveal the caret.
expect
(
outerController
.
offset
,
outerController
.
position
.
maxScrollExtent
);
expect
(
editableScrollController
.
offset
,
0
);
});
testWidgets
(
'bringIntoView centers the viewport on caret when the caret is wider than the viewport'
,
(
WidgetTester
tester
)
async
{
const
String
text
=
'to coz ze ze Szwecji'
;
final
TextEditingController
controller
=
TextEditingController
(
text:
text
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Align
(
alignment:
Alignment
.
topLeft
,
child:
SizedBox
(
width:
32.0
,
height:
100.0
,
child:
EditableText
(
showSelectionHandles:
true
,
controller:
controller
,
focusNode:
FocusNode
(),
style:
const
TextStyle
(
fontFamily:
'Ahem'
,
fontSize:
48.0
,
height:
1.0
),
cursorColor:
Colors
.
blue
,
cursorWidth:
48.0
,
backgroundCursorColor:
Colors
.
grey
,
selectionControls:
materialTextSelectionControls
,
keyboardType:
TextInputType
.
text
,
),
),
),
));
final
EditableTextState
state
=
tester
.
state
<
EditableTextState
>(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
state
.
renderEditable
;
final
Scrollable
scrollable
=
tester
.
widget
<
Scrollable
>(
find
.
byType
(
Scrollable
));
expect
(
scrollable
.
controller
!.
position
.
viewportDimension
,
equals
(
32.0
));
expect
(
scrollable
.
controller
!.
offset
,
0.0
);
expect
(
renderEditable
.
maxScrollExtent
,
equals
(
977.0
));
state
.
bringIntoView
(
const
TextPosition
(
offset:
2
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
2
*
48.0
+
48.0
/
2
-
32.0
/
2
);
state
.
bringIntoView
(
const
TextPosition
(
offset:
5
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
5
*
48.0
+
48.0
/
2
-
32.0
/
2
);
state
.
bringIntoView
(
const
TextPosition
(
offset:
7
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
7
*
48.0
+
48.0
/
2
-
32.0
/
2
);
state
.
bringIntoView
(
const
TextPosition
(
offset:
9
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
9
*
48.0
+
48.0
/
2
-
32.0
/
2
);
});
testWidgets
(
'bringIntoView centers the viewport on caret when the caret is taller than the viewport'
,
(
WidgetTester
tester
)
async
{
const
String
text
=
'to
\n
coz
\n
ze
\n
ze
\n
Szwecji'
;
final
TextEditingController
controller
=
TextEditingController
(
text:
text
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Align
(
alignment:
Alignment
.
topLeft
,
child:
SizedBox
(
width:
500.0
,
height:
32.0
,
child:
EditableText
(
showSelectionHandles:
true
,
maxLines:
null
,
controller:
controller
,
focusNode:
FocusNode
(),
style:
const
TextStyle
(
fontFamily:
'Ahem'
,
fontSize:
48.0
,
height:
1.0
),
cursorColor:
Colors
.
blue
,
backgroundCursorColor:
Colors
.
grey
,
selectionControls:
materialTextSelectionControls
,
keyboardType:
TextInputType
.
text
,
),
),
),
));
final
EditableTextState
state
=
tester
.
state
<
EditableTextState
>(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
state
.
renderEditable
;
final
Scrollable
scrollable
=
tester
.
widget
<
Scrollable
>(
find
.
byType
(
Scrollable
));
expect
(
scrollable
.
controller
!.
position
.
viewportDimension
,
equals
(
32.0
));
expect
(
scrollable
.
controller
!.
offset
,
0.0
);
expect
(
renderEditable
.
maxScrollExtent
,
equals
(
208.0
));
state
.
bringIntoView
(
const
TextPosition
(
offset:
3
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
48.0
+
48.0
/
2
-
32.0
/
2
);
state
.
bringIntoView
(
const
TextPosition
(
offset:
7
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
2
*
48.0
+
48.0
/
2
-
32.0
/
2
);
state
.
bringIntoView
(
const
TextPosition
(
offset:
10
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
3
*
48.0
+
48.0
/
2
-
32.0
/
2
);
state
.
bringIntoView
(
const
TextPosition
(
offset:
13
));
await
tester
.
pumpAndSettle
();
expect
(
scrollable
.
controller
!.
offset
,
4
*
48.0
+
48.0
/
2
-
32.0
/
2
);
});
testWidgets
(
'bringIntoView does nothing if the physics prohibits implicit scrolling'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
controller
=
TextEditingController
(
text:
testText
*
20
);
final
ScrollController
scrollController
=
ScrollController
();
...
...
@@ -6208,6 +6109,7 @@ void main() {
));
}
await
buildWithPhysics
();
expect
(
scrollController
.
offset
,
0
);
...
...
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