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
fd41d419
Unverified
Commit
fd41d419
authored
Feb 22, 2022
by
chunhtai
Committed by
GitHub
Feb 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getOffsetForCaret to return correct value if contains widget span (#98542)
parent
9dc9cf57
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
4 deletions
+26
-4
placeholder_span.dart
packages/flutter/lib/src/painting/placeholder_span.dart
+4
-1
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+2
-2
widget_span.dart
packages/flutter/lib/src/widgets/widget_span.dart
+2
-1
text_painter_test.dart
packages/flutter/test/painting/text_painter_test.dart
+18
-0
No files found.
packages/flutter/lib/src/painting/placeholder_span.dart
View file @
fd41d419
...
...
@@ -41,6 +41,9 @@ abstract class PlaceholderSpan extends InlineSpan {
TextStyle
?
style
,
})
:
super
(
style:
style
);
/// The unicode character to represent a placeholder.
static
const
String
placeholderCodeUnit
=
'
\
uFFFC'
;
/// How the placeholder aligns vertically with the text.
///
/// See [ui.PlaceholderAlignment] for details on each mode.
...
...
@@ -57,7 +60,7 @@ abstract class PlaceholderSpan extends InlineSpan {
@override
void
computeToPlainText
(
StringBuffer
buffer
,
{
bool
includeSemanticsLabels
=
true
,
bool
includePlaceholders
=
true
})
{
if
(
includePlaceholders
)
{
buffer
.
write
(
'
\
uFFFC'
);
buffer
.
write
(
placeholderCodeUnit
);
}
}
...
...
packages/flutter/lib/src/painting/text_painter.dart
View file @
fd41d419
...
...
@@ -739,7 +739,7 @@ class TextPainter {
// Get the Rect of the cursor (in logical pixels) based off the near edge
// of the character upstream from the given string offset.
Rect
?
_getRectFromUpstream
(
int
offset
,
Rect
caretPrototype
)
{
final
String
flattenedText
=
_text
!.
toPlainText
(
include
Placeholder
s:
false
);
final
String
flattenedText
=
_text
!.
toPlainText
(
include
SemanticsLabel
s:
false
);
final
int
?
prevCodeUnit
=
_text
!.
codeUnitAt
(
max
(
0
,
offset
-
1
));
if
(
prevCodeUnit
==
null
)
return
null
;
...
...
@@ -789,7 +789,7 @@ class TextPainter {
// Get the Rect of the cursor (in logical pixels) based off the near edge
// of the character downstream from the given string offset.
Rect
?
_getRectFromDownstream
(
int
offset
,
Rect
caretPrototype
)
{
final
String
flattenedText
=
_text
!.
toPlainText
(
include
Placeholder
s:
false
);
final
String
flattenedText
=
_text
!.
toPlainText
(
include
SemanticsLabel
s:
false
);
// We cap the offset at the final index of the _text.
final
int
?
nextCodeUnit
=
_text
!.
codeUnitAt
(
min
(
offset
,
flattenedText
.
length
-
1
));
if
(
nextCodeUnit
==
null
)
...
...
packages/flutter/lib/src/widgets/widget_span.dart
View file @
fd41d419
...
...
@@ -139,7 +139,8 @@ class WidgetSpan extends PlaceholderSpan {
@override
int
?
codeUnitAtVisitor
(
int
index
,
Accumulator
offset
)
{
return
null
;
offset
.
increment
(
1
);
return
PlaceholderSpan
.
placeholderCodeUnit
.
codeUnitAt
(
0
);
}
@override
...
...
packages/flutter/test/painting/text_painter_test.dart
View file @
fd41d419
...
...
@@ -37,6 +37,24 @@ void main() {
expect
(
caretOffset
.
dx
,
painter
.
width
);
});
test
(
'TextPainter caret test with WidgetSpan'
,
()
{
// Regression test for https://github.com/flutter/flutter/issues/98458.
final
TextPainter
painter
=
TextPainter
()
..
textDirection
=
TextDirection
.
ltr
;
painter
.
text
=
const
TextSpan
(
children:
<
InlineSpan
>[
TextSpan
(
text:
'before'
),
WidgetSpan
(
child:
Text
(
'widget'
)),
TextSpan
(
text:
'after'
),
]);
painter
.
setPlaceholderDimensions
(
const
<
PlaceholderDimensions
>[
PlaceholderDimensions
(
size:
Size
(
50
,
30
),
baselineOffset:
25
,
alignment:
ui
.
PlaceholderAlignment
.
bottom
),
]);
painter
.
layout
();
final
Offset
caretOffset
=
painter
.
getOffsetForCaret
(
ui
.
TextPosition
(
offset:
painter
.
text
!.
toPlainText
().
length
),
ui
.
Rect
.
zero
);
expect
(
caretOffset
.
dx
,
painter
.
width
);
},
skip:
isBrowser
&&
!
isCanvasKit
);
// https://github.com/flutter/flutter/issues/56308
test
(
'TextPainter null text test'
,
()
{
final
TextPainter
painter
=
TextPainter
()
..
textDirection
=
TextDirection
.
ltr
;
...
...
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