@@ -1543,24 +1543,120 @@ - (void)testUpdateFirstRectForRange {
1543
1543
[inputView firstRectForRange: range]));
1544
1544
}
1545
1545
1546
- - (void )testFirstRectForRangeReturnsCorrectSelectionRect {
1546
+ - (void )testFirstRectForRangeReturnsCorrectSelectionRectOnASingleLineLeftToRight {
1547
1547
FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] initWithOwner: textInputPlugin];
1548
1548
[inputView setTextInputState: @{@" text" : @" COMPOSING" }];
1549
1549
1550
- FlutterTextRange* range = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 1 )];
1551
- CGRect testRect = CGRectMake (100 , 100 , 100 , 100 );
1552
1550
[inputView setSelectionRects: @[
1553
1551
[FlutterTextSelectionRect selectionRectWithRect: CGRectMake (0 , 0 , 100 , 100 ) position: 0U ],
1554
- [FlutterTextSelectionRect selectionRectWithRect: testRect position: 1U ],
1555
- [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 200 , 100 , 100 ) position: 2U ],
1552
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (100 , 0 , 100 , 100 ) position: 1U ],
1553
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 0 , 100 , 100 ) position: 2U ],
1554
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (300 , 0 , 100 , 100 ) position: 3U ],
1556
1555
]];
1557
- XCTAssertTrue (CGRectEqualToRect (testRect, [inputView firstRectForRange: range]));
1556
+ FlutterTextRange* singleRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 1 )];
1557
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (100 , 0 , 100 , 100 ),
1558
+ [inputView firstRectForRange: singleRectRange]));
1559
+
1560
+ FlutterTextRange* multiRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 3 )];
1561
+
1562
+ if (@available (iOS 17 , *)) {
1563
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (100 , 0 , 300 , 100 ),
1564
+ [inputView firstRectForRange: multiRectRange]));
1565
+ } else {
1566
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (100 , 0 , 100 , 100 ),
1567
+ [inputView firstRectForRange: multiRectRange]));
1568
+ }
1558
1569
1559
1570
[inputView setTextInputState: @{@" text" : @" COM" }];
1560
1571
FlutterTextRange* rangeOutsideBounds = [FlutterTextRange rangeWithNSRange: NSMakeRange (3 , 1 )];
1561
1572
XCTAssertTrue (CGRectEqualToRect (CGRectZero, [inputView firstRectForRange: rangeOutsideBounds]));
1562
1573
}
1563
1574
1575
+ - (void )testFirstRectForRangeReturnsCorrectSelectionRectOnASingleLineRightToLeft {
1576
+ FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] initWithOwner: textInputPlugin];
1577
+ [inputView setTextInputState: @{@" text" : @" COMPOSING" }];
1578
+
1579
+ [inputView setSelectionRects: @[
1580
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (300 , 0 , 100 , 100 ) position: 0U ],
1581
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 0 , 100 , 100 ) position: 1U ],
1582
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (100 , 0 , 100 , 100 ) position: 2U ],
1583
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (0 , 0 , 100 , 100 ) position: 3U ],
1584
+ ]];
1585
+ FlutterTextRange* singleRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 1 )];
1586
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (200 , 0 , 100 , 100 ),
1587
+ [inputView firstRectForRange: singleRectRange]));
1588
+
1589
+ FlutterTextRange* multiRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 3 )];
1590
+ if (@available (iOS 17 , *)) {
1591
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (0 , 0 , 300 , 100 ),
1592
+ [inputView firstRectForRange: multiRectRange]));
1593
+ } else {
1594
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (200 , 0 , 100 , 100 ),
1595
+ [inputView firstRectForRange: multiRectRange]));
1596
+ }
1597
+
1598
+ [inputView setTextInputState: @{@" text" : @" COM" }];
1599
+ FlutterTextRange* rangeOutsideBounds = [FlutterTextRange rangeWithNSRange: NSMakeRange (3 , 1 )];
1600
+ XCTAssertTrue (CGRectEqualToRect (CGRectZero, [inputView firstRectForRange: rangeOutsideBounds]));
1601
+ }
1602
+
1603
+ - (void )testFirstRectForRangeReturnsCorrectSelectionRectOnMultipleLinesLeftToRight {
1604
+ FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] initWithOwner: textInputPlugin];
1605
+ [inputView setTextInputState: @{@" text" : @" COMPOSING" }];
1606
+
1607
+ [inputView setSelectionRects: @[
1608
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (0 , 0 , 100 , 100 ) position: 0U ],
1609
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (100 , 0 , 100 , 100 ) position: 1U ],
1610
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 0 , 100 , 100 ) position: 2U ],
1611
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (300 , 0 , 100 , 100 ) position: 3U ],
1612
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (0 , 100 , 100 , 100 ) position: 4U ],
1613
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (100 , 100 , 100 , 100 ) position: 5U ],
1614
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 100 , 100 , 100 ) position: 6U ],
1615
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (300 , 100 , 100 , 100 ) position: 7U ],
1616
+ ]];
1617
+ FlutterTextRange* singleRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 1 )];
1618
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (100 , 0 , 100 , 100 ),
1619
+ [inputView firstRectForRange: singleRectRange]));
1620
+
1621
+ FlutterTextRange* multiRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 4 )];
1622
+
1623
+ if (@available (iOS 17 , *)) {
1624
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (100 , 0 , 300 , 100 ),
1625
+ [inputView firstRectForRange: multiRectRange]));
1626
+ } else {
1627
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (100 , 0 , 100 , 100 ),
1628
+ [inputView firstRectForRange: multiRectRange]));
1629
+ }
1630
+ }
1631
+
1632
+ - (void )testFirstRectForRangeReturnsCorrectSelectionRectOnMultipleLinesRightToLeft {
1633
+ FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] initWithOwner: textInputPlugin];
1634
+ [inputView setTextInputState: @{@" text" : @" COMPOSING" }];
1635
+
1636
+ [inputView setSelectionRects: @[
1637
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (300 , 0 , 100 , 100 ) position: 0U ],
1638
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 0 , 100 , 100 ) position: 1U ],
1639
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (100 , 0 , 100 , 100 ) position: 2U ],
1640
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (0 , 0 , 100 , 100 ) position: 3U ],
1641
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (300 , 100 , 100 , 100 ) position: 4U ],
1642
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (200 , 100 , 100 , 100 ) position: 5U ],
1643
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (100 , 100 , 100 , 100 ) position: 6U ],
1644
+ [FlutterTextSelectionRect selectionRectWithRect: CGRectMake (0 , 100 , 100 , 100 ) position: 7U ],
1645
+ ]];
1646
+ FlutterTextRange* singleRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 1 )];
1647
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (200 , 0 , 100 , 100 ),
1648
+ [inputView firstRectForRange: singleRectRange]));
1649
+
1650
+ FlutterTextRange* multiRectRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (1 , 4 )];
1651
+ if (@available (iOS 17 , *)) {
1652
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (0 , 0 , 300 , 100 ),
1653
+ [inputView firstRectForRange: multiRectRange]));
1654
+ } else {
1655
+ XCTAssertTrue (CGRectEqualToRect (CGRectMake (200 , 0 , 100 , 100 ),
1656
+ [inputView firstRectForRange: multiRectRange]));
1657
+ }
1658
+ }
1659
+
1564
1660
- (void )testClosestPositionToPoint {
1565
1661
FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] initWithOwner: textInputPlugin];
1566
1662
[inputView setTextInputState: @{@" text" : @" COMPOSING" }];
0 commit comments