@@ -1539,4 +1539,125 @@ public void CtrlKey_With_AssociatedText_Does_Not_Insert_Into_TextField ()
15391539
15401540 Assert . Equal ( "" , tf . Text ) ;
15411541 }
1542+
1543+ [ Fact ]
1544+ public void ReadOnly_ShouldNotAllowAutomaticallyScrolling_AndMustSetInsertionPointToZeroAtInitialization ( )
1545+ {
1546+ TextField tf = new ( ) { Width = 5 , ReadOnly = true , Text = "hello world" } ;
1547+ tf . BeginInit ( ) ;
1548+ tf . EndInit ( ) ;
1549+
1550+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1551+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1552+ Assert . Null ( tf . SelectedText ) ;
1553+ }
1554+
1555+ [ Fact ]
1556+ public void ReadOnly_ShouldNotSelectAllText_OnFocus ( )
1557+ {
1558+ TextField tf = new ( ) { Width = 5 , ReadOnly = true , Text = "hello world" } ;
1559+ tf . BeginInit ( ) ;
1560+ tf . EndInit ( ) ;
1561+
1562+ tf . SetFocus ( ) ;
1563+
1564+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1565+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1566+ Assert . Null ( tf . SelectedText ) ;
1567+ }
1568+
1569+ [ Fact ]
1570+ public void ReadOnly_ShouldSetInsertionPointAndScrollOffsetToZero_OnFocus ( )
1571+ {
1572+ TextField tf = new ( ) { Width = 5 , ReadOnly = true , Text = "hello world" } ;
1573+ tf . BeginInit ( ) ;
1574+ tf . EndInit ( ) ;
1575+
1576+ // Move insertion point to end of text
1577+ tf . InsertionPoint = tf . Text . Length ;
1578+ Assert . Equal ( 11 , tf . InsertionPoint ) ;
1579+ Assert . Equal ( 7 , tf . ScrollOffset ) ;
1580+
1581+ // Set focus and verify insertion point is still at zero
1582+ tf . SetFocus ( ) ;
1583+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1584+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1585+ }
1586+
1587+ [ Fact ]
1588+ public void ReadOnly_ShouldSetInsertionPointAndScrollOffsetToZero_LeavingFocus ( )
1589+ {
1590+ TextField tf = new ( ) { Width = 5 , ReadOnly = true , Text = "hello world" } ;
1591+
1592+ // Create another view to take focus away
1593+ View otherView = new ( ) { CanFocus = true } ;
1594+
1595+ // Create a container to hold both views
1596+ Runnable container = new ( ) { Id = "container" , Width = 20 , Height = 5 } ;
1597+ container . Add ( tf , otherView ) ;
1598+ container . BeginInit ( ) ;
1599+ container . EndInit ( ) ;
1600+
1601+ // Set focus to TextField and verify insertion point and scroll offset are at zero
1602+ tf . SetFocus ( ) ;
1603+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1604+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1605+
1606+ // Move insertion point to end of text and then move focus away to verify insertion point is still at zero
1607+ tf . InsertionPoint = tf . Text . Length ;
1608+ Assert . Equal ( 11 , tf . InsertionPoint ) ;
1609+ Assert . Equal ( 7 , tf . ScrollOffset ) ;
1610+
1611+ otherView . SetFocus ( ) ;
1612+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1613+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1614+ }
1615+
1616+ [ Fact ]
1617+ public void ReadOnly_ShouldSetInsertionPointAndScrollOffsetToZero_AfterCopyingText ( )
1618+ {
1619+ TextField tf = new ( ) { Width = 5 , ReadOnly = true , Text = "hello world" } ;
1620+ tf . BeginInit ( ) ;
1621+ tf . EndInit ( ) ;
1622+
1623+ // Select all text
1624+ tf . SelectAll ( ) ;
1625+ Assert . Equal ( 11 , tf . InsertionPoint ) ;
1626+ Assert . Equal ( 7 , tf . ScrollOffset ) ;
1627+ Assert . Equal ( "hello world" , tf . SelectedText ) ;
1628+
1629+ // Copy text and verify insertion point and scroll offset are still at zero
1630+ tf . Copy ( ) ;
1631+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1632+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1633+ Assert . Null ( tf . SelectedText ) ;
1634+ }
1635+
1636+ [ Fact ]
1637+ public void ReadOnly_ShouldSetInsertionPointAndScrollOffsetToZeroAndClearAllSelection_OnLeavingFocus ( )
1638+ {
1639+ TextField tf = new ( ) { Width = 5 , ReadOnly = true , Text = "hello world" } ;
1640+
1641+ // Create another view to take focus away
1642+ View otherView = new ( ) { CanFocus = true } ;
1643+
1644+ // Create a container to hold both views
1645+ Runnable container = new ( ) { Id = "container" , Width = 20 , Height = 5 } ;
1646+ container . Add ( tf , otherView ) ;
1647+ container . BeginInit ( ) ;
1648+ container . EndInit ( ) ;
1649+
1650+ // Set focus to TextField and select all text
1651+ tf . SetFocus ( ) ;
1652+ tf . SelectAll ( ) ;
1653+ Assert . Equal ( 11 , tf . InsertionPoint ) ;
1654+ Assert . Equal ( 7 , tf . ScrollOffset ) ;
1655+ Assert . Equal ( "hello world" , tf . SelectedText ) ;
1656+
1657+ // Move focus away and verify insertion point and scroll offset are at zero and selection is cleared
1658+ otherView . SetFocus ( ) ;
1659+ Assert . Equal ( 0 , tf . InsertionPoint ) ;
1660+ Assert . Equal ( 0 , tf . ScrollOffset ) ;
1661+ Assert . Null ( tf . SelectedText ) ;
1662+ }
15421663}
0 commit comments