diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 66bca7fb42..bfaad7f38e 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2384,7 +2384,7 @@ void Insert (Rune rune) } var prow = currentRow - topRow; if (!wrapNeeded) { - SetNeedsDisplay (new Rect (0, prow, Frame.Width, prow + 1)); + SetNeedsDisplay (new Rect (0, prow, Math.Max (Frame.Width, 0), Math.Max (prow + 1, 0))); } } diff --git a/UnitTests/TextViewTests.cs b/UnitTests/TextViewTests.cs index ba00845b34..5584e66bb5 100644 --- a/UnitTests/TextViewTests.cs +++ b/UnitTests/TextViewTests.cs @@ -5707,5 +5707,25 @@ public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero () }); Assert.Null (exception); } + + [Fact] + [AutoInitShutdown] + public void ScrollDownTillCaretOffscreen_ThenType () + { + var tv = new TextView { + Width = 10, + Height = 5 + }; + + // add 100 lines of wide text to view + for (int i = 0; i < 100; i++) + tv.Text += new string ('x', 100) + Environment.NewLine; + + Assert.Equal (0, tv.CursorPosition.Y); + tv.ScrollTo (50); + Assert.Equal (0, tv.CursorPosition.Y); + + tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ())); + } } } \ No newline at end of file