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
0f8148ec
Unverified
Commit
0f8148ec
authored
Apr 18, 2021
by
LongCatIsLooong
Committed by
GitHub
Apr 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RenderEditable] Dont paint caret when selection is invalid (#79607)
parent
f4c74a6e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
4 deletions
+50
-4
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+5
-4
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+45
-0
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
0f8148ec
...
...
@@ -3703,7 +3703,10 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
_clipRectLayer
=
null
;
_paintContents
(
context
,
offset
);
}
_paintHandleLayers
(
context
,
getEndpointsForSelection
(
selection
!));
final
TextSelection
?
selection
=
this
.
selection
;
if
(
selection
!=
null
)
{
_paintHandleLayers
(
context
,
getEndpointsForSelection
(
selection
));
}
}
ClipRectLayer
?
_clipRectLayer
;
...
...
@@ -4060,9 +4063,7 @@ class _FloatingCursorPainter extends RenderEditablePainter {
assert
(
renderEditable
!=
null
);
final
TextSelection
?
selection
=
renderEditable
.
selection
;
// TODO(LongCatIsLooong): skip painting the caret when the selection is
// (-1, -1).
if
(
selection
==
null
||
!
selection
.
isCollapsed
)
if
(
selection
==
null
||
!
selection
.
isCollapsed
||
!
selection
.
isValid
)
return
;
final
Rect
?
floatingCursorRect
=
this
.
floatingCursorRect
;
...
...
packages/flutter/test/rendering/editable_test.dart
View file @
0f8148ec
...
...
@@ -412,6 +412,51 @@ void main() {
expect
(
editable
,
paintsExactlyCountTimes
(
#drawRect
,
1
));
});
test
(
'does not paint the caret when selection is null'
,
()
async
{
final
TextSelectionDelegate
delegate
=
FakeEditableTextState
();
final
ValueNotifier
<
bool
>
showCursor
=
ValueNotifier
<
bool
>(
true
);
final
RenderEditable
editable
=
RenderEditable
(
backgroundCursorColor:
Colors
.
grey
,
selectionColor:
Colors
.
black
,
paintCursorAboveText:
true
,
textDirection:
TextDirection
.
ltr
,
cursorColor:
Colors
.
red
,
showCursor:
showCursor
,
offset:
ViewportOffset
.
zero
(),
textSelectionDelegate:
delegate
,
text:
const
TextSpan
(
text:
'test'
,
style:
TextStyle
(
height:
1.0
,
fontSize:
10.0
,
fontFamily:
'Ahem'
,
),
),
startHandleLayerLink:
LayerLink
(),
endHandleLayerLink:
LayerLink
(),
selection:
const
TextSelection
.
collapsed
(
offset:
2
,
affinity:
TextAffinity
.
upstream
,
),
);
layout
(
editable
);
expect
(
editable
,
paints
..
paragraph
()
// Red collapsed cursor is painted, not a selection box.
..
rect
(
color:
Colors
.
red
[
500
]),
);
// Let the RenderEditable paint again. Setting the selection to null should
// prevent the caret from being painted.
editable
.
selection
=
null
;
// Still paints the paragraph.
expect
(
editable
,
paints
..
paragraph
());
// No longer paints the caret.
expect
(
editable
,
isNot
(
paints
..
rect
(
color:
Colors
.
red
[
500
])));
});
test
(
'selects correct place with offsets'
,
()
{
const
String
text
=
'test
\n
test'
;
final
TextSelectionDelegate
delegate
=
FakeEditableTextState
()
...
...
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