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
bc4cacac
Unverified
Commit
bc4cacac
authored
Aug 05, 2023
by
Tomasz Gucio
Committed by
GitHub
Aug 05, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take paint offset into account for inline children hit test in Editable (#131675)
parent
545ecd29
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
2 deletions
+85
-2
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+2
-2
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+83
-0
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
bc4cacac
...
...
@@ -1916,9 +1916,9 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
@override
@protected
bool
hitTestChildren
(
BoxHitTestResult
result
,
{
required
Offset
position
})
{
final
Offset
effectivePosition
=
position
-
_paintOffset
;
final
InlineSpan
?
textSpan
=
_textPainter
.
text
;
if
(
textSpan
!=
null
)
{
final
Offset
effectivePosition
=
position
-
_paintOffset
;
final
TextPosition
textPosition
=
_textPainter
.
getPositionForOffset
(
effectivePosition
);
final
Object
?
span
=
textSpan
.
getSpanForPosition
(
textPosition
);
if
(
span
is
HitTestTarget
)
{
...
...
@@ -1926,7 +1926,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
return
true
;
}
}
return
hitTestInlineChildren
(
result
,
p
osition
);
return
hitTestInlineChildren
(
result
,
effectiveP
osition
);
}
late
TapGestureRecognizer
_tap
;
...
...
packages/flutter/test/rendering/editable_test.dart
View file @
bc4cacac
...
...
@@ -1721,6 +1721,89 @@ void main() {
editable
.
hitTest
(
result
,
position:
const
Offset
(
5.0
,
15.0
));
expect
(
result
.
path
,
hasLength
(
0
));
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/61020
test
(
'hits correct WidgetSpan when scrolled'
,
()
{
final
String
text
=
'
${"\n" * 10}
test'
;
final
TextSelectionDelegate
delegate
=
_FakeEditableTextState
()
..
textEditingValue
=
TextEditingValue
(
text:
text
,
selection:
const
TextSelection
.
collapsed
(
offset:
13
),
);
final
List
<
RenderBox
>
renderBoxes
=
<
RenderBox
>[
RenderParagraph
(
const
TextSpan
(
text:
'a'
),
textDirection:
TextDirection
.
ltr
),
RenderParagraph
(
const
TextSpan
(
text:
'b'
),
textDirection:
TextDirection
.
ltr
),
RenderParagraph
(
const
TextSpan
(
text:
'c'
),
textDirection:
TextDirection
.
ltr
),
];
final
RenderEditable
editable
=
RenderEditable
(
maxLines:
null
,
text:
TextSpan
(
style:
const
TextStyle
(
height:
1.0
,
fontSize:
10.0
),
children:
<
InlineSpan
>[
TextSpan
(
text:
text
),
const
WidgetSpan
(
child:
Text
(
'a'
)),
const
TextSpan
(
children:
<
InlineSpan
>[
WidgetSpan
(
child:
Text
(
'b'
)),
WidgetSpan
(
child:
Text
(
'c'
)),
],
),
],
),
startHandleLayerLink:
LayerLink
(),
endHandleLayerLink:
LayerLink
(),
textDirection:
TextDirection
.
ltr
,
offset:
ViewportOffset
.
fixed
(
100.0
),
// equal to the height of the 10 empty lines
textSelectionDelegate:
delegate
,
selection:
const
TextSelection
.
collapsed
(
offset:
0
,
),
children:
renderBoxes
,
);
_applyParentData
(
renderBoxes
,
editable
.
text
!);
layout
(
editable
,
constraints:
BoxConstraints
.
loose
(
const
Size
(
500.0
,
500.0
)));
// Prepare for painting after layout.
pumpFrame
(
phase:
EnginePhase
.
compositingBits
);
BoxHitTestResult
result
=
BoxHitTestResult
();
editable
.
hitTest
(
result
,
position:
Offset
.
zero
);
// We expect two hit test entries in the path because the RenderEditable
// will add itself as well.
expect
(
result
.
path
,
hasLength
(
2
));
HitTestTarget
target
=
result
.
path
.
first
.
target
;
expect
(
target
,
isA
<
TextSpan
>());
expect
((
target
as
TextSpan
).
text
,
text
);
// Only testing the RenderEditable entry here once, not anymore below.
expect
(
result
.
path
.
last
.
target
,
isA
<
RenderEditable
>());
result
=
BoxHitTestResult
();
editable
.
hitTest
(
result
,
position:
const
Offset
(
15.0
,
0.0
));
expect
(
result
.
path
,
hasLength
(
2
));
target
=
result
.
path
.
first
.
target
;
expect
(
target
,
isA
<
TextSpan
>());
expect
((
target
as
TextSpan
).
text
,
text
);
result
=
BoxHitTestResult
();
editable
.
hitTest
(
result
,
position:
const
Offset
(
41.0
,
0.0
));
expect
(
result
.
path
,
hasLength
(
3
));
target
=
result
.
path
.
first
.
target
;
expect
(
target
,
isA
<
TextSpan
>());
expect
((
target
as
TextSpan
).
text
,
'a'
);
result
=
BoxHitTestResult
();
editable
.
hitTest
(
result
,
position:
const
Offset
(
55.0
,
0.0
));
expect
(
result
.
path
,
hasLength
(
3
));
target
=
result
.
path
.
first
.
target
;
expect
(
target
,
isA
<
TextSpan
>());
expect
((
target
as
TextSpan
).
text
,
'b'
);
result
=
BoxHitTestResult
();
editable
.
hitTest
(
result
,
position:
const
Offset
(
69.0
,
5.0
));
expect
(
result
.
path
,
hasLength
(
3
));
target
=
result
.
path
.
first
.
target
;
expect
(
target
,
isA
<
TextSpan
>());
expect
((
target
as
TextSpan
).
text
,
'c'
);
result
=
BoxHitTestResult
();
editable
.
hitTest
(
result
,
position:
const
Offset
(
5.0
,
15.0
));
expect
(
result
.
path
,
hasLength
(
2
));
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/61020
});
test
(
'does not skip TextPainter.layout because of invalid cache'
,
()
{
...
...
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