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
fa7340a3
Unverified
Commit
fa7340a3
authored
Oct 02, 2019
by
Gary Qian
Committed by
GitHub
Oct 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return WidgetSpans from getSpanForPosition (#40635)
parent
fe46eba6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
2 deletions
+37
-2
paragraph.dart
packages/flutter/lib/src/rendering/paragraph.dart
+8
-2
widget_span.dart
packages/flutter/lib/src/widgets/widget_span.dart
+4
-0
text_span_test.dart
packages/flutter/test/painting/text_span_test.dart
+25
-0
No files found.
packages/flutter/lib/src/rendering/paragraph.dart
View file @
fa7340a3
...
...
@@ -442,8 +442,14 @@ class RenderParagraph extends RenderBox
_layoutTextWithConstraints
(
constraints
);
final
Offset
offset
=
entry
.
localPosition
;
final
TextPosition
position
=
_textPainter
.
getPositionForOffset
(
offset
);
final
TextSpan
span
=
_textPainter
.
text
.
getSpanForPosition
(
position
);
span
?.
recognizer
?.
addPointer
(
event
);
final
InlineSpan
span
=
_textPainter
.
text
.
getSpanForPosition
(
position
);
if
(
span
==
null
)
{
return
;
}
if
(
span
is
TextSpan
)
{
final
TextSpan
textSpan
=
span
;
textSpan
.
recognizer
?.
addPointer
(
event
);
}
}
bool
_needsClipping
=
false
;
...
...
packages/flutter/lib/src/widgets/widget_span.dart
View file @
fa7340a3
...
...
@@ -128,6 +128,10 @@ class WidgetSpan extends PlaceholderSpan {
@override
InlineSpan
getSpanForPositionVisitor
(
TextPosition
position
,
Accumulator
offset
)
{
if
(
position
.
offset
==
offset
.
value
)
{
return
this
;
}
offset
.
increment
(
1
);
return
null
;
}
...
...
packages/flutter/test/painting/text_span_test.dart
View file @
fa7340a3
...
...
@@ -209,4 +209,29 @@ void main() {
expect
(
textSpan1
.
compareTo
(
textSpan1
),
RenderComparison
.
identical
);
expect
(
textSpan2
.
compareTo
(
textSpan2
),
RenderComparison
.
identical
);
});
test
(
'GetSpanForPosition with WidgetSpan'
,
()
{
const
TextSpan
textSpan
=
TextSpan
(
text:
'a'
,
children:
<
InlineSpan
>[
TextSpan
(
text:
'b'
),
WidgetSpan
(
child:
Text
.
rich
(
TextSpan
(
children:
<
InlineSpan
>[
WidgetSpan
(
child:
SizedBox
(
width:
10
,
height:
10
)),
TextSpan
(
text:
'The sky is falling :)'
),
],
),
),
),
TextSpan
(
text:
'c'
),
],
);
expect
(
textSpan
.
getSpanForPosition
(
const
TextPosition
(
offset:
0
)).
runtimeType
,
TextSpan
);
expect
(
textSpan
.
getSpanForPosition
(
const
TextPosition
(
offset:
1
)).
runtimeType
,
TextSpan
);
expect
(
textSpan
.
getSpanForPosition
(
const
TextPosition
(
offset:
2
)).
runtimeType
,
WidgetSpan
);
expect
(
textSpan
.
getSpanForPosition
(
const
TextPosition
(
offset:
3
)).
runtimeType
,
TextSpan
);
});
}
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