2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'dart:math' as math;
5
6
import 'dart:ui' as ui show Gradient, Shader, TextBox, PlaceholderAlignment;
6
7
7
8
import 'package:flutter/foundation.dart' ;
@@ -766,12 +767,23 @@ class RenderParagraph extends RenderBox
766
767
final TextDirection initialDirection = currentDirection;
767
768
final TextSelection selection = TextSelection (baseOffset: start, extentOffset: end);
768
769
final List <ui.TextBox > rects = getBoxesForSelection (selection);
769
- Rect rect;
770
- for (ui.TextBox textBox in rects) {
771
- rect ?? = textBox.toRect ();
770
+ if (rects.isEmpty) {
771
+ return null ;
772
+ }
773
+ Rect rect = rects.first.toRect ();
774
+ currentDirection = rects.first.direction;
775
+ for (ui.TextBox textBox in rects.skip (1 )) {
772
776
rect = rect.expandToInclude (textBox.toRect ());
773
777
currentDirection = textBox.direction;
774
778
}
779
+ // Any of the text boxes may have had infinite dimensions.
780
+ // We shouldn't pass infinite dimensions up to the bridges.
781
+ rect = Rect .fromLTWH (
782
+ math.max (0.0 , rect.left),
783
+ math.max (0.0 , rect.top),
784
+ math.min (rect.width, constraints.maxWidth),
785
+ math.min (rect.height, constraints.maxHeight),
786
+ );
775
787
// round the current rectangle to make this API testable and add some
776
788
// padding so that the accessibility rects do not overlap with the text.
777
789
// TODO(jonahwilliams): implement this for all text accessibility rects.
@@ -798,12 +810,18 @@ class RenderParagraph extends RenderBox
798
810
if (current != start) {
799
811
final SemanticsNode node = SemanticsNode ();
800
812
final SemanticsConfiguration configuration = buildSemanticsConfig (current, start);
813
+ if (configuration == null ) {
814
+ continue ;
815
+ }
801
816
node.updateWith (config: configuration);
802
817
node.rect = currentRect;
803
818
newChildren.add (node);
804
819
}
805
820
final dynamic inlineElement = _inlineSemanticsElements[j];
806
821
final SemanticsConfiguration configuration = buildSemanticsConfig (start, end);
822
+ if (configuration == null ) {
823
+ continue ;
824
+ }
807
825
if (inlineElement != null ) {
808
826
// Add semantics for this recognizer.
809
827
final SemanticsNode node = SemanticsNode ();
@@ -842,9 +860,11 @@ class RenderParagraph extends RenderBox
842
860
if (current < rawLabel.length) {
843
861
final SemanticsNode node = SemanticsNode ();
844
862
final SemanticsConfiguration configuration = buildSemanticsConfig (current, rawLabel.length);
845
- node.updateWith (config: configuration);
846
- node.rect = currentRect;
847
- newChildren.add (node);
863
+ if (configuration != null ) {
864
+ node.updateWith (config: configuration);
865
+ node.rect = currentRect;
866
+ newChildren.add (node);
867
+ }
848
868
}
849
869
node.updateWith (config: config, childrenInInversePaintOrder: newChildren);
850
870
}
0 commit comments