@@ -547,6 +547,60 @@ void testMain() async {
547547 );
548548 });
549549 });
550+
551+ group ('$CanvasParagraph .getLineBoundary' , () {
552+ test ('single-line' , () {
553+ final CanvasParagraph paragraph = rich (ahemStyle, (builder) {
554+ builder.addText ('One single line' );
555+ })
556+ ..layout (constrain (400.0 ));
557+
558+ // "One single line".length == 15
559+ for (int i = 0 ; i < 15 ; i++ ) {
560+ expect (
561+ paragraph.getLineBoundary (ui.TextPosition (offset: i)),
562+ ui.TextRange (start: 0 , end: 15 ),
563+ reason: 'failed at offset $i ' ,
564+ );
565+ }
566+ });
567+
568+ test ('multi-line' , () {
569+ final CanvasParagraph paragraph = rich (ahemStyle, (builder) {
570+ builder.addText ('First line\n ' );
571+ builder.addText ('Second line\n ' );
572+ builder.addText ('Third line' );
573+ })
574+ ..layout (constrain (400.0 ));
575+
576+ // "First line\n".length == 11
577+ for (int i = 0 ; i < 11 ; i++ ) {
578+ expect (
579+ paragraph.getLineBoundary (ui.TextPosition (offset: i)),
580+ ui.TextRange (start: 0 , end: 11 ),
581+ reason: 'failed at offset $i ' ,
582+ );
583+ }
584+
585+ // "Second line\n".length == 12
586+ for (int i = 11 ; i < 23 ; i++ ) {
587+ expect (
588+ paragraph.getLineBoundary (ui.TextPosition (offset: i)),
589+ ui.TextRange (start: 11 , end: 23 ),
590+ reason: 'failed at offset $i ' ,
591+ );
592+ }
593+
594+ // "Third line".length == 10
595+ for (int i = 23 ; i < 33 ; i++ ) {
596+ expect (
597+ paragraph.getLineBoundary (ui.TextPosition (offset: i)),
598+ ui.TextRange (start: 23 , end: 33 ),
599+ reason: 'failed at offset $i ' ,
600+ );
601+ }
602+ });
603+ });
550604}
551605
552606/// Shortcut to create a [ui.TextBox] with an optional [ui.TextDirection] .
0 commit comments