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
22f88809
Unverified
Commit
22f88809
authored
Feb 15, 2019
by
xster
Committed by
GitHub
Feb 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure the selection is still painted under the text (#27970)
parent
d1371cd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
8 deletions
+102
-8
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+17
-8
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+85
-0
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
22f88809
...
...
@@ -1544,19 +1544,28 @@ class RenderEditable extends RenderBox {
assert
(
_textLayoutLastWidth
==
constraints
.
maxWidth
);
final
Offset
effectiveOffset
=
offset
+
_paintOffset
;
bool
showSelection
=
false
;
bool
showCaret
=
false
;
if
(
_selection
!=
null
&&
!
_floatingCursorOn
)
{
if
(
_selection
.
isCollapsed
&&
_showCursor
.
value
&&
cursorColor
!=
null
)
showCaret
=
true
;
else
if
(!
_selection
.
isCollapsed
&&
_selectionColor
!=
null
)
showSelection
=
true
;
}
if
(
showSelection
)
{
_selectionRects
??=
_textPainter
.
getBoxesForSelection
(
_selection
);
_paintSelection
(
context
.
canvas
,
effectiveOffset
);
}
// On iOS, the cursor is painted over the text, on Android, it's painted
// under it.
if
(
paintCursorAboveText
)
_textPainter
.
paint
(
context
.
canvas
,
effectiveOffset
);
if
(
_selection
!=
null
&&
!
_floatingCursorOn
)
{
if
(
_selection
.
isCollapsed
&&
_showCursor
.
value
&&
cursorColor
!=
null
)
{
_paintCaret
(
context
.
canvas
,
effectiveOffset
,
_selection
.
extent
);
}
else
if
(!
_selection
.
isCollapsed
&&
_selectionColor
!=
null
)
{
_selectionRects
??=
_textPainter
.
getBoxesForSelection
(
_selection
);
_paintSelection
(
context
.
canvas
,
effectiveOffset
);
}
}
if
(
showCaret
)
_paintCaret
(
context
.
canvas
,
effectiveOffset
,
_selection
.
extent
);
if
(!
paintCursorAboveText
)
_textPainter
.
paint
(
context
.
canvas
,
effectiveOffset
);
...
...
packages/flutter/test/rendering/editable_test.dart
View file @
22f88809
...
...
@@ -168,4 +168,89 @@ void main() {
expect
(
editable
,
paintsExactlyCountTimes
(
#drawRRect
,
0
));
});
test
(
'text is painted above selection'
,
()
{
final
TextSelectionDelegate
delegate
=
FakeEditableTextState
();
final
RenderEditable
editable
=
RenderEditable
(
backgroundCursorColor:
Colors
.
grey
,
selectionColor:
Colors
.
black
,
textDirection:
TextDirection
.
ltr
,
cursorColor:
const
Color
.
fromARGB
(
0xFF
,
0xFF
,
0x00
,
0x00
),
offset:
ViewportOffset
.
zero
(),
textSelectionDelegate:
delegate
,
text:
const
TextSpan
(
text:
'test'
,
style:
TextStyle
(
height:
1.0
,
fontSize:
10.0
,
fontFamily:
'Ahem'
,
),
),
selection:
const
TextSelection
(
baseOffset:
0
,
extentOffset:
3
,
affinity:
TextAffinity
.
upstream
,
),
);
layout
(
editable
);
expect
(
editable
,
paints
// This is a big selection rectangle, not the cursor.
..
rect
(
color:
Colors
.
black
,
rect:
Rect
.
fromLTWH
(
0
,
0
,
30
,
10
))
..
paragraph
(),
);
// There is exactly one rect paint (1 selection, 0 cursor).
expect
(
editable
,
paintsExactlyCountTimes
(
#drawRect
,
1
));
});
test
(
'cursor can paint above or below the text'
,
()
{
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'
,
),
),
selection:
const
TextSelection
.
collapsed
(
offset:
2
,
affinity:
TextAffinity
.
upstream
,
),
);
layout
(
editable
);
expect
(
editable
,
paints
..
paragraph
()
..
rect
(
color:
Colors
.
red
[
500
],
rect:
Rect
.
fromLTWH
(
20
,
2
,
1
,
6
)),
);
// There is exactly one rect paint (0 selection, 1 cursor).
expect
(
editable
,
paintsExactlyCountTimes
(
#drawRect
,
1
));
editable
.
paintCursorAboveText
=
false
;
pumpFrame
();
expect
(
editable
,
// The paint order is now flipped.
paints
..
rect
(
color:
Colors
.
red
[
500
],
rect:
Rect
.
fromLTWH
(
20
,
2
,
1
,
6
))
..
paragraph
(),
);
expect
(
editable
,
paintsExactlyCountTimes
(
#drawRect
,
1
));
});
}
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