From 90afc5e854ea0681dc0625987a4cd9062359dfae Mon Sep 17 00:00:00 2001 From: Tomasz Gucio <72562119+tgucio@users.noreply.github.com> Date: Tue, 30 May 2023 19:32:10 +0200 Subject: [PATCH] Take paint offset into account for Editable children (#127843) --- .../flutter/lib/src/rendering/editable.dart | 2 +- .../flutter/test/rendering/editable_test.dart | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index cf76e38f0b..09fea17285 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -2459,7 +2459,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, } _textPainter.paint(context.canvas, effectiveOffset); - paintInlineChildren(context, offset); + paintInlineChildren(context, effectiveOffset); if (foregroundChild != null) { context.paintChild(foregroundChild, offset); diff --git a/packages/flutter/test/rendering/editable_test.dart b/packages/flutter/test/rendering/editable_test.dart index 0007d7a843..8093fe6192 100644 --- a/packages/flutter/test/rendering/editable_test.dart +++ b/packages/flutter/test/rendering/editable_test.dart @@ -1558,6 +1558,45 @@ void main() { expect(composingRect, null); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021 + test('WidgetSpan render box is painted at correct offset when scrolled', () async { + final TextSelectionDelegate delegate = _FakeEditableTextState() + ..textEditingValue = const TextEditingValue( + text: 'test', + selection: TextSelection.collapsed(offset: 3), + ); + final List renderBoxes = [ + RenderParagraph(const TextSpan(text: 'b'), textDirection: TextDirection.ltr), + ]; + final ViewportOffset viewportOffset = ViewportOffset.fixed(100.0); + final RenderEditable editable = RenderEditable( + backgroundCursorColor: Colors.grey, + selectionColor: Colors.black, + textDirection: TextDirection.ltr, + cursorColor: Colors.red, + offset: viewportOffset, + textSelectionDelegate: delegate, + startHandleLayerLink: LayerLink(), + endHandleLayerLink: LayerLink(), + maxLines: null, + text: TextSpan( + style: const TextStyle(height: 1.0, fontSize: 10.0), + children: [ + const TextSpan(text: 'test'), + WidgetSpan(child: Container(width: 10, height: 10, color: Colors.blue)), + ], + ), + selection: const TextSelection.collapsed(offset: 3), + children: renderBoxes, + ); + _applyParentData(renderBoxes, editable.text!); + layout(editable); + editable.hasFocus = true; + pumpFrame(); + + final Rect composingRect = editable.getRectForComposingRange(const TextRange(start: 4, end: 5))!; + expect(composingRect, const Rect.fromLTRB(40.0, -100.0, 54.0, -86.0)); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021 + test('can compute IntrinsicWidth for WidgetSpans', () { // Regression test for https://github.com/flutter/flutter/issues/59316 const double screenWidth = 1000.0;