Commit 5de581c6 authored by Matt Perry's avatar Matt Perry

Fix text selection painting to draw what the engine tells us. (#4397)

BUG=https://github.com/flutter/flutter/issues/4321
BUG=https://github.com/flutter/flutter/issues/4349
parent 48ed80b3
...@@ -148,10 +148,10 @@ class RenderEditableLine extends RenderBox { ...@@ -148,10 +148,10 @@ class RenderEditableLine extends RenderBox {
List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) { List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) {
// TODO(mpcomplete): We should be more disciplined about when we dirty the // TODO(mpcomplete): We should be more disciplined about when we dirty the
// layout state of the text painter so that we can know that the layout is // layout state of the text painter so that we can know that the layout is
// clean at this point. // clean at this point.
_textPainter.layout(); _textPainter.layout();
Offset offset = _paintOffset + new Offset(0.0, -_kCaretHeightOffset); Offset offset = _paintOffset;
if (selection.isCollapsed) { if (selection.isCollapsed) {
// TODO(mpcomplete): This doesn't work well at an RTL/LTR boundary. // TODO(mpcomplete): This doesn't work well at an RTL/LTR boundary.
...@@ -278,15 +278,8 @@ class RenderEditableLine extends RenderBox { ...@@ -278,15 +278,8 @@ class RenderEditableLine extends RenderBox {
void _paintSelection(Canvas canvas, Offset effectiveOffset) { void _paintSelection(Canvas canvas, Offset effectiveOffset) {
assert(_selectionRects != null); assert(_selectionRects != null);
Paint paint = new Paint()..color = _selectionColor; Paint paint = new Paint()..color = _selectionColor;
for (ui.TextBox box in _selectionRects) { for (ui.TextBox box in _selectionRects)
Rect selectionRect = new Rect.fromLTWH( canvas.drawRect(box.toRect().shift(effectiveOffset), paint);
effectiveOffset.dx + box.left,
effectiveOffset.dy + _kCaretHeightOffset,
box.right - box.left,
size.height - 2.0 * _kCaretHeightOffset
);
canvas.drawRect(selectionRect, paint);
}
} }
void _paintContents(PaintingContext context, Offset offset) { void _paintContents(PaintingContext context, Offset offset) {
......
...@@ -192,7 +192,7 @@ void main() { ...@@ -192,7 +192,7 @@ void main() {
List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection( List<TextSelectionPoint> endpoints = renderLine.getEndpointsForSelection(
new TextSelection.collapsed(offset: offset)); new TextSelection.collapsed(offset: offset));
expect(endpoints.length, 1); expect(endpoints.length, 1);
return endpoints[0].point; return endpoints[0].point + new Offset(0.0, -2.0);
} }
testWidgets('Can long press to select', (WidgetTester tester) async { testWidgets('Can long press to select', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment