Skip to content

TextPainter.getBoxesForSelection reports wrong TextBoxes on web #66089

@LongCatIsLooong

Description

@LongCatIsLooong

The following test I'm trying to add only fails on web. And the only TextBox textPainter.getBoxesForSelection reports is [TextBox.fromLTRBD(0.0, 0.0, 0.0, 0.0, TextDirection.ltr)].

class FakeEditableTextState with TextSelectionDelegate {
  @override
  TextEditingValue textEditingValue = const TextEditingValue();

  @override
  void hideToolbar() { }

  @override
  void bringIntoView(TextPosition position) { }
}

    test('more than 1 run on the same line', () {
      final TextSelectionDelegate delegate = FakeEditableTextState();
      final RenderEditable editable = RenderEditable(
        maxLines: null,
        textAlign: TextAlign.start,
        textDirection: TextDirection.ltr,
        offset: ViewportOffset.zero(),
        textSelectionDelegate: delegate,
        startHandleLayerLink: LayerLink(),
        endHandleLayerLink: LayerLink(),
      );

      const TextStyle tinyText = TextStyle(fontSize: 1, fontFamily: 'Ahem');
      const TextStyle normalText = TextStyle(fontSize: 10, fontFamily: 'Ahem');
      editable.text = TextSpan(
        children: <TextSpan>[
          const TextSpan(text: 'A', style: tinyText),
          TextSpan(text: 'A' * 20, style: normalText),
          const TextSpan(text: 'A', style: tinyText)
        ],
      );
      // Give it a width that forces the editable to wrap.
      editable.layout(const BoxConstraints.tightFor(width: 200));

      final Rect composingRect = editable.getRectForComposingRange(const TextRange(start: 0, end: 20 + 2));

      // Since the range covers an entire line, the Rect should also be almost
      // as wide as the entire paragraph (give or take 1 character).
      expect(composingRect?.width, greaterThan(200 - 10));
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsa: typographyText rendering, possibly libtxtplatform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions