From 57fc939e22cc5f2155da6a941b3410c4a81e48b9 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 21 Jul 2022 13:55:51 +0100 Subject: [PATCH] Fixes #1866. Bug when scrolling text and type in a TextView. (#1868) --- Terminal.Gui/Views/TextView.cs | 2 +- UnitTests/TextViewTests.cs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 66bca7fb4..bfaad7f38 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2384,7 +2384,7 @@ namespace Terminal.Gui { } 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 ba00845b3..5584e66bb 100644 --- a/UnitTests/TextViewTests.cs +++ b/UnitTests/TextViewTests.cs @@ -5707,5 +5707,25 @@ line. }); 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