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
e70a1d1d
Unverified
Commit
e70a1d1d
authored
Jun 10, 2021
by
Gary Qian
Committed by
GitHub
Jun 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support WidgetSpan in RenderEditable (#83537)
parent
18b15788
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
703 additions
and
102 deletions
+703
-102
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+277
-64
paragraph.dart
packages/flutter/lib/src/rendering/paragraph.dart
+6
-12
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+24
-11
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+3
-3
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+385
-4
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+8
-8
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
e70a1d1d
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/rendering/paragraph.dart
View file @
e70a1d1d
...
...
@@ -18,7 +18,7 @@ import 'object.dart';
const
String
_kEllipsis
=
'
\
u2026'
;
/// Parent data for use with [RenderParagraph].
/// Parent data for use with [RenderParagraph]
and [RenderEditable]
.
class
TextParentData
extends
ContainerBoxParentData
<
RenderBox
>
{
/// The scaling of the text.
double
?
scale
;
...
...
@@ -434,14 +434,12 @@ class RenderParagraph extends RenderBox
@override
bool
hitTestChildren
(
BoxHitTestResult
result
,
{
required
Offset
position
})
{
// Hit test text spans.
late
final
bool
hitText
;
bool
hitText
=
false
;
final
TextPosition
textPosition
=
_textPainter
.
getPositionForOffset
(
position
);
final
InlineSpan
?
span
=
_textPainter
.
text
!.
getSpanForPosition
(
textPosition
);
if
(
span
!=
null
&&
span
is
HitTestTarget
)
{
result
.
add
(
HitTestEntry
(
span
as
HitTestTarget
));
hitText
=
true
;
}
else
{
hitText
=
false
;
}
// Hit test render object children
...
...
@@ -545,16 +543,14 @@ class RenderParagraph extends RenderBox
);
childSize
=
child
.
size
;
switch
(
_placeholderSpans
[
childIndex
].
alignment
)
{
case
ui
.
PlaceholderAlignment
.
baseline
:
{
case
ui
.
PlaceholderAlignment
.
baseline
:
baselineOffset
=
child
.
getDistanceToBaseline
(
_placeholderSpans
[
childIndex
].
baseline
!,
);
break
;
}
default
:
{
default
:
baselineOffset
=
null
;
break
;
}
}
}
else
{
assert
(
_placeholderSpans
[
childIndex
].
alignment
!=
ui
.
PlaceholderAlignment
.
baseline
);
...
...
@@ -597,14 +593,12 @@ class RenderParagraph extends RenderBox
switch
(
span
.
alignment
)
{
case
ui
.
PlaceholderAlignment
.
baseline
:
case
ui
.
PlaceholderAlignment
.
aboveBaseline
:
case
ui
.
PlaceholderAlignment
.
belowBaseline
:
{
case
ui
.
PlaceholderAlignment
.
belowBaseline
:
return
false
;
}
case
ui
.
PlaceholderAlignment
.
top
:
case
ui
.
PlaceholderAlignment
.
middle
:
case
ui
.
PlaceholderAlignment
.
bottom
:
{
case
ui
.
PlaceholderAlignment
.
bottom
:
continue
;
}
}
}
return
true
;
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
e70a1d1d
...
...
@@ -31,6 +31,7 @@ import 'text.dart';
import
'text_editing_action.dart'
;
import
'text_selection.dart'
;
import
'ticker_provider.dart'
;
import
'widget_span.dart'
;
export
'package:flutter/services.dart'
show
SelectionChangedCause
,
TextEditingValue
,
TextSelection
,
TextInputType
,
SmartQuotesType
,
SmartDashesType
;
...
...
@@ -197,9 +198,8 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
if
(!
value
.
isComposingRangeValid
||
!
withComposing
)
{
return
TextSpan
(
style:
style
,
text:
text
);
}
final
TextStyle
composingStyle
=
style
!.
merge
(
const
TextStyle
(
decoration:
TextDecoration
.
underline
),
);
final
TextStyle
composingStyle
=
style
?.
merge
(
const
TextStyle
(
decoration:
TextDecoration
.
underline
))
??
const
TextStyle
(
decoration:
TextDecoration
.
underline
);
return
TextSpan
(
style:
style
,
children:
<
TextSpan
>[
...
...
@@ -2651,7 +2651,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
key:
_editableKey
,
startHandleLayerLink:
_startHandleLayerLink
,
endHandleLayerLink:
_endHandleLayerLink
,
text
Span:
buildTextSpan
(),
inline
Span:
buildTextSpan
(),
value:
_value
,
cursorColor:
_cursorColor
,
backgroundCursorColor:
widget
.
backgroundCursorColor
,
...
...
@@ -2730,10 +2730,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
}
}
class
_Editable
extends
Leaf
RenderObjectWidget
{
const
_Editable
({
class
_Editable
extends
MultiChild
RenderObjectWidget
{
_Editable
({
Key
?
key
,
required
this
.
text
Span
,
required
this
.
inline
Span
,
required
this
.
value
,
required
this
.
startHandleLayerLink
,
required
this
.
endHandleLayerLink
,
...
...
@@ -2778,9 +2778,22 @@ class _Editable extends LeafRenderObjectWidget {
required
this
.
clipBehavior
,
})
:
assert
(
textDirection
!=
null
),
assert
(
rendererIgnoresPointer
!=
null
),
super
(
key:
key
);
super
(
key:
key
,
children:
_extractChildren
(
inlineSpan
));
// Traverses the InlineSpan tree and depth-first collects the list of
// child widgets that are created in WidgetSpans.
static
List
<
Widget
>
_extractChildren
(
InlineSpan
span
)
{
final
List
<
Widget
>
result
=
<
Widget
>[];
span
.
visitChildren
((
InlineSpan
span
)
{
if
(
span
is
WidgetSpan
)
{
result
.
add
(
span
.
child
);
}
return
true
;
});
return
result
;
}
final
TextSpan
text
Span
;
final
InlineSpan
inline
Span
;
final
TextEditingValue
value
;
final
Color
?
cursorColor
;
final
LayerLink
startHandleLayerLink
;
...
...
@@ -2827,7 +2840,7 @@ class _Editable extends LeafRenderObjectWidget {
@override
RenderEditable
createRenderObject
(
BuildContext
context
)
{
return
RenderEditable
(
text:
text
Span
,
text:
inline
Span
,
cursorColor:
cursorColor
,
startHandleLayerLink:
startHandleLayerLink
,
endHandleLayerLink:
endHandleLayerLink
,
...
...
@@ -2872,7 +2885,7 @@ class _Editable extends LeafRenderObjectWidget {
@override
void
updateRenderObject
(
BuildContext
context
,
RenderEditable
renderObject
)
{
renderObject
..
text
=
text
Span
..
text
=
inline
Span
..
cursorColor
=
cursorColor
..
startHandleLayerLink
=
startHandleLayerLink
..
endHandleLayerLink
=
endHandleLayerLink
...
...
packages/flutter/test/material/text_field_test.dart
View file @
e70a1d1d
...
...
@@ -1056,12 +1056,12 @@ void main() {
await
tester
.
pump
();
String
editText
=
findRenderEditable
(
tester
).
text
!
.
text
!;
String
editText
=
(
findRenderEditable
(
tester
).
text
!
as
TextSpan
)
.
text
!;
expect
(
editText
.
substring
(
editText
.
length
-
1
),
newChar
);
await
tester
.
pump
(
const
Duration
(
seconds:
2
));
editText
=
findRenderEditable
(
tester
).
text
!
.
text
!;
editText
=
(
findRenderEditable
(
tester
).
text
!
as
TextSpan
)
.
text
!;
expect
(
editText
.
substring
(
editText
.
length
-
1
),
'
\
u2022'
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
android
}));
...
...
@@ -1096,7 +1096,7 @@ void main() {
await
tester
.
pump
();
final
String
editText
=
findRenderEditable
(
tester
).
text
!
.
text
!;
final
String
editText
=
(
findRenderEditable
(
tester
).
text
!
as
TextSpan
)
.
text
!;
expect
(
editText
.
substring
(
editText
.
length
-
1
),
'
\
u2022'
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
macOS
,
...
...
packages/flutter/test/rendering/editable_test.dart
View file @
e70a1d1d
This diff is collapsed.
Click to expand it.
packages/flutter/test/widgets/editable_text_test.dart
View file @
e70a1d1d
...
...
@@ -2841,7 +2841,7 @@ void main() {
),
));
expect
(
findRenderEditable
(
tester
).
text
!
.
text
,
expectedValue
);
expect
(
(
findRenderEditable
(
tester
).
text
!
as
TextSpan
)
.
text
,
expectedValue
);
expect
(
semantics
,
...
...
@@ -2906,7 +2906,7 @@ void main() {
));
final
String
expectedValue
=
obscuringCharacter
*
originalText
.
length
;
expect
(
findRenderEditable
(
tester
).
text
!
.
text
,
expectedValue
);
expect
(
(
findRenderEditable
(
tester
).
text
!
as
TextSpan
)
.
text
,
expectedValue
);
});
group
(
'a11y copy/cut/paste'
,
()
{
...
...
@@ -3808,17 +3808,17 @@ void main() {
final
RenderEditable
renderEditable
=
findRenderEditable
(
tester
);
// The actual text span is split into 3 parts with the middle part underlined.
expect
(
renderEditable
.
text
!
.
children
!.
length
,
3
);
final
TextSpan
textSpan
=
renderEditable
.
text
!
.
children
![
1
]
as
TextSpan
;
expect
(
(
renderEditable
.
text
!
as
TextSpan
)
.
children
!.
length
,
3
);
final
TextSpan
textSpan
=
(
renderEditable
.
text
!
as
TextSpan
)
.
children
![
1
]
as
TextSpan
;
expect
(
textSpan
.
text
,
'composing'
);
expect
(
textSpan
.
style
!.
decoration
,
TextDecoration
.
underline
);
focusNode
.
unfocus
();
await
tester
.
pump
();
expect
(
renderEditable
.
text
!
.
children
,
isNull
);
// Everything's just format
t
ed the same way now.
expect
(
renderEditable
.
text
!
.
text
,
'text composing text'
);
expect
(
(
renderEditable
.
text
!
as
TextSpan
)
.
children
,
isNull
);
// Everything's just formated the same way now.
expect
(
(
renderEditable
.
text
!
as
TextSpan
)
.
text
,
'text composing text'
);
expect
(
renderEditable
.
text
!.
style
!.
decoration
,
isNull
);
});
...
...
@@ -6137,7 +6137,7 @@ void main() {
));
final
RenderEditable
renderEditable
=
findRenderEditable
(
tester
);
final
TextSpan
textSpan
=
renderEditable
.
text
!;
final
TextSpan
textSpan
=
renderEditable
.
text
!
as
TextSpan
;
expect
(
textSpan
.
style
!.
color
,
color
);
});
});
...
...
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