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
93a11777
Unverified
Commit
93a11777
authored
Feb 03, 2022
by
Jason Simmons
Committed by
GitHub
Feb 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Invalidate the TextPainter line metrics cache when redoing text layout (#97446)
parent
6aed693c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
+23
-2
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+2
-1
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+1
-1
text_painter_test.dart
packages/flutter/test/painting/text_painter_test.dart
+20
-0
No files found.
packages/flutter/lib/src/painting/text_painter.dart
View file @
93a11777
...
...
@@ -648,7 +648,8 @@ class TextPainter {
_createParagraph
();
_lastMinWidth
=
minWidth
;
_lastMaxWidth
=
maxWidth
;
// A change in layout invalidates the cached caret metrics as well.
// A change in layout invalidates the cached caret and line metrics as well.
_lineMetricsCache
=
null
;
_previousCaretPosition
=
null
;
_previousCaretPrototype
=
null
;
_layoutParagraph
(
minWidth
,
maxWidth
);
...
...
packages/flutter/lib/src/rendering/editable.dart
View file @
93a11777
...
...
@@ -2416,7 +2416,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
// ui.LineMetrics, then we can get rid of this.
final
Offset
offset
=
_textPainter
.
getOffsetForCaret
(
startPosition
,
Rect
.
zero
);
for
(
final
ui
.
LineMetrics
lineMetrics
in
metrics
)
{
if
(
lineMetrics
.
baseline
+
lineMetrics
.
descent
>
offset
.
dy
)
{
if
(
lineMetrics
.
baseline
>
offset
.
dy
)
{
return
MapEntry
<
int
,
Offset
>(
lineMetrics
.
lineNumber
,
Offset
(
offset
.
dx
,
lineMetrics
.
baseline
));
}
}
...
...
packages/flutter/test/painting/text_painter_test.dart
View file @
93a11777
...
...
@@ -996,6 +996,26 @@ void main() {
ui
.
Rect
.
zero
);
expect
(
caretOffset
.
dx
,
painter
.
width
);
},
skip:
kIsWeb
&&
!
isCanvasKit
);
// https://github.com/flutter/flutter/issues/87545
test
(
'TextPainter line metrics update after layout'
,
()
{
final
TextPainter
painter
=
TextPainter
()
..
textDirection
=
TextDirection
.
ltr
;
const
String
text
=
'word1 word2 word3'
;
painter
.
text
=
const
TextSpan
(
text:
text
,
);
painter
.
layout
(
maxWidth:
80
);
List
<
ui
.
LineMetrics
>
lines
=
painter
.
computeLineMetrics
();
expect
(
lines
.
length
,
3
);
painter
.
layout
(
maxWidth:
1000
);
lines
=
painter
.
computeLineMetrics
();
expect
(
lines
.
length
,
1
);
},
skip:
kIsWeb
&&
!
isCanvasKit
);
// https://github.com/flutter/flutter/issues/62819
}
class
MockCanvas
extends
Fake
implements
Canvas
{
...
...
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