diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 7751aedcd..8b4f17424 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2717,6 +2717,7 @@ public class TextView : View _isReadOnly = value; SetNeedsDisplay (); + WrapTextModel (); Adjust (); } } @@ -2859,7 +2860,7 @@ public class TextView : View if (_wordWrap) { _wrapManager = new (_model); - _model = _wrapManager.WrapModel (Viewport.Width, out _, out _, out _, out _); + WrapTextModel (); } else if (!_wordWrap && _wrapManager is { }) { @@ -4074,7 +4075,7 @@ public class TextView : View need = true; } else if (!_wordWrap - && (CurrentColumn - _leftColumn > Viewport.Width + offB.width || dSize.size >= Viewport.Width + offB.width)) + && (CurrentColumn - _leftColumn + 1 > Viewport.Width + offB.width || dSize.size + 1 >= Viewport.Width + offB.width)) { _leftColumn = TextModel.CalculateLeftColumn ( line, @@ -4458,7 +4459,7 @@ public class TextView : View CurrentColumn - _leftColumn, CurrentRow - _topRow, Viewport.Width, - CurrentRow - _topRow + 1 + Math.Max (CurrentRow - _topRow + 1, 0) ) ); } @@ -5321,7 +5322,7 @@ public class TextView : View private void MoveEndOfLine () { List currentLine = GetCurrentLine (); - CurrentColumn = currentLine.Count; + CurrentColumn = Math.Max (currentLine.Count - (ReadOnly ? 1 : 0), 0); Adjust (); DoNeededAction (); } @@ -5345,7 +5346,7 @@ public class TextView : View } List currentLine = GetCurrentLine (); - CurrentColumn = currentLine.Count; + CurrentColumn = Math.Max (currentLine.Count - (ReadOnly ? 1 : 0), 0); } } @@ -5433,7 +5434,7 @@ public class TextView : View { List currentLine = GetCurrentLine (); - if (CurrentColumn < currentLine.Count) + if ((ReadOnly ? CurrentColumn + 1 : CurrentColumn) < currentLine.Count) { CurrentColumn++; } @@ -5801,7 +5802,7 @@ public class TextView : View if (idx - _leftColumn >= r.Count) { - CurrentColumn = Math.Max (r.Count - _leftColumn, 0); + CurrentColumn = Math.Max (r.Count - _leftColumn - (ReadOnly ? 1 : 0), 0); } else { @@ -6445,7 +6446,7 @@ public class TextView : View if (_wordWrap && _wrapManager is { }) { _model = _wrapManager.WrapModel ( - Viewport.Width, + Math.Max (Viewport.Width - (ReadOnly ? 0 : 1), 0), // For the cursor on the last column of a line out int nRow, out int nCol, out int nStartRow, diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index e628f561a..479a8112a 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -8944,13 +8944,12 @@ line. TestHelpers.AssertDriverContentsWithFrameAre ( @" -This is -the first -line. -This is -the -second -line. +This is +the first +line. +This is +the second +line. ", _output );