Browse Source

Fixes the auto-size text bug. (#1603)

* Fixes the auto-size text bug.

* The superview is responsible to clearing the previous frame.
BDisp 3 năm trước cách đây
mục cha
commit
0168a3c054
2 tập tin đã thay đổi với 29 bổ sung1 xóa
  1. 1 1
      Terminal.Gui/Core/View.cs
  2. 28 0
      UnitTests/ViewTests.cs

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -1414,7 +1414,7 @@ namespace Terminal.Gui {
 				if (textFormatter != null) {
 					textFormatter.NeedsFormat = true;
 				}
-				textFormatter?.Draw (ViewToScreen (bounds), HasFocus ? ColorScheme.Focus : GetNormalColor (),
+				textFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? ColorScheme.Focus : GetNormalColor (),
 					HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled);
 			}
 

+ 28 - 0
UnitTests/ViewTests.cs

@@ -1601,5 +1601,33 @@ namespace Terminal.Gui.Views {
 			Assert.Equal (top1, v1.GetTopSuperView ());
 			Assert.Equal (top2, v2.GetTopSuperView ());
 		}
+
+		[Fact]
+		[AutoInitShutdown]
+		public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
+		{
+			var lbl = new Label ("123");
+			Application.Top.Add (lbl);
+			Application.Begin (Application.Top);
+
+			Assert.Equal ("123 ", GetContents ());
+
+			lbl.Text = "12";
+
+			if (!lbl.SuperView.NeedDisplay.IsEmpty) {
+				lbl.SuperView.Redraw (lbl.SuperView.NeedDisplay);
+			}
+
+			Assert.Equal ("12  ", GetContents ());
+
+			string GetContents ()
+			{
+				var text = "";
+				for (int i = 0; i < 4; i++) {
+					text += (char)Application.Driver.Contents [0, i, 0];
+				}
+				return text;
+			}
+		}
 	}
 }