Browse Source

Avoid throwing when WordWrap is true on constructor initialization.

BDisp 3 years ago
parent
commit
205fbf4d5b
2 changed files with 16 additions and 2 deletions
  1. 2 2
      Terminal.Gui/Views/TextView.cs
  2. 14 0
      UnitTests/TextViewTests.cs

+ 2 - 2
Terminal.Gui/Views/TextView.cs

@@ -1456,7 +1456,7 @@ namespace Terminal.Gui {
 				model.LoadString (value);
 				if (wordWrap) {
 					wrapManager = new WordWrapManager (model);
-					model = wrapManager.WrapModel (Frame.Width - 2, out _, out _, out _, out _);
+					model = wrapManager.WrapModel (Math.Max (Frame.Width - 2, 0), out _, out _, out _, out _);
 				}
 				TextChanged?.Invoke ();
 				SetNeedsDisplay ();
@@ -1478,7 +1478,7 @@ namespace Terminal.Gui {
 		void WrapTextModel ()
 		{
 			if (wordWrap && wrapManager != null) {
-				model = wrapManager.WrapModel (Frame.Width - 2,
+				model = wrapManager.WrapModel (Math.Max (Frame.Width - 2, 0),
 					out int nRow, out int nCol,
 					out int nStartRow, out int nStartCol,
 					currentRow, currentColumn,

+ 14 - 0
UnitTests/TextViewTests.cs

@@ -5693,5 +5693,19 @@ line.
 			Assert.Equal ($"1{Environment.NewLine}2", tv.Text);
 			Assert.Equal ($"1{Environment.NewLine}2", tv.SelectedText);
 		}
+
+		[Fact, AutoInitShutdown]
+		public void WordWrap_Not_Throw_If_Width_Is_Less_Than_Zero ()
+		{
+			var exception = Record.Exception (() => {
+				var tv = new TextView () {
+					Width = Dim.Fill (),
+					Height = Dim.Fill (),
+					WordWrap = true,
+					Text = "これは、左右のクリップ境界をテストするための非常に長いテキストです。"
+				};
+			});
+			Assert.Null (exception);
+		}
 	}
 }