Browse Source

Fixes #1866. Bug when scrolling text and type in a TextView. (#1868)

BDisp 3 năm trước cách đây
mục cha
commit
57fc939e22
2 tập tin đã thay đổi với 21 bổ sung1 xóa
  1. 1 1
      Terminal.Gui/Views/TextView.cs
  2. 20 0
      UnitTests/TextViewTests.cs

+ 1 - 1
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)));
 			}
 		}
 

+ 20 - 0
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 ()));
+		}
 	}
 }