Tigger Kindel 2 年之前
父节点
当前提交
38fd0a61ae

+ 10 - 0
Terminal.Gui/Core/Application.cs

@@ -1173,6 +1173,7 @@ namespace Terminal.Gui {
 			_initialized = false;
 			mouseGrabView = null;
 			_enableConsoleScrolling = false;
+			lastMouseOwnerView = null;
 
 			// Reset synchronization context to allow the user to run async/await,
 			// as the main loop has been ended, the synchronization context from 
@@ -1280,6 +1281,15 @@ namespace Terminal.Gui {
 				}
 				state.Toplevel.SetNeedsDisplay (state.Toplevel.Bounds);
 			}
+			if (toplevels.Count == 1 && state.Toplevel == Top
+				&& (Driver.Cols != state.Toplevel.Frame.Width || Driver.Rows != state.Toplevel.Frame.Height)
+				&& (!state.Toplevel.NeedDisplay.IsEmpty || state.Toplevel.ChildNeedsDisplay || state.Toplevel.LayoutNeeded)) {
+
+				Driver.SetAttribute (Colors.TopLevel.Normal);
+				state.Toplevel.Clear (new Rect (0, 0, Driver.Cols, Driver.Rows));
+
+			}
+
 			if (!state.Toplevel._needsDisplay.IsEmpty || state.Toplevel._childNeedsDisplay || state.Toplevel.LayoutNeeded
 				|| MdiChildNeedsDisplay ()) {
 				state.Toplevel.Redraw (state.Toplevel.Bounds);

+ 2 - 2
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -327,8 +327,8 @@ namespace UICatalog.Scenarios {
 				};
 				Add (listView);
 
-				start = new Button ("Start") { IsDefault = true };
-				start.Clicked += (s,e) => {
+				start = new Button ("Start") { IsDefault = true, ClearOnVisibleFalse = false };
+				start.Clicked += (s, e) => {
 					Staging = new Staging (DateTime.Now);
 					RequestStop ();
 				};

+ 85 - 0
UnitTests/TopLevels/ToplevelTests.cs

@@ -1364,5 +1364,90 @@ namespace Terminal.Gui.TopLevelTests {
            
  CTRL-N New", output);
 		}
+
+		[Fact, AutoInitShutdown]
+		public void Single_Smaller_Top_Will_Have_Cleaning_Trails_Chunk_On_Move ()
+		{
+			var dialog = new Dialog ("Single smaller Dialog") { Width = 30, Height = 10 };
+			dialog.Add (new Label (
+				"How should I've to react. Cleaning all chunk trails or setting the 'Cols' and 'Rows' to this dialog length?\n" +
+				"Cleaning is more easy to fix this.") {
+				X = Pos.Center (),
+				Y = Pos.Center (),
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+				TextAlignment = TextAlignment.Centered,
+				VerticalTextAlignment = VerticalTextAlignment.Middle,
+				AutoSize = false
+			});
+
+			var rs = Application.Begin (dialog);
+
+			Assert.Null (Application.MouseGrabView);
+			Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+                         ┌ Single smaller Dialog ─────┐
+                         │ How should I've to react.  │
+                         │Cleaning all chunk trails or│
+                         │   setting the 'Cols' and   │
+                         │   'Rows' to this dialog    │
+                         │          length?           │
+                         │Cleaning is more easy to fix│
+                         │           this.            │
+                         │                            │
+                         └────────────────────────────┘", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 25,
+					Y = 7,
+					Flags = MouseFlags.Button1Pressed
+				});
+
+			var firstIteration = false;
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration); Assert.Equal (dialog, Application.MouseGrabView);
+
+			Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+                         ┌ Single smaller Dialog ─────┐
+                         │ How should I've to react.  │
+                         │Cleaning all chunk trails or│
+                         │   setting the 'Cols' and   │
+                         │   'Rows' to this dialog    │
+                         │          length?           │
+                         │Cleaning is more easy to fix│
+                         │           this.            │
+                         │                            │
+                         └────────────────────────────┘", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 20,
+					Y = 10,
+					Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+				});
+
+			firstIteration = false;
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			Assert.Equal (dialog, Application.MouseGrabView);
+			Assert.Equal (new Rect (20, 10, 30, 10), dialog.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+                    ┌ Single smaller Dialog ─────┐
+                    │ How should I've to react.  │
+                    │Cleaning all chunk trails or│
+                    │   setting the 'Cols' and   │
+                    │   'Rows' to this dialog    │
+                    │          length?           │
+                    │Cleaning is more easy to fix│
+                    │           this.            │
+                    │                            │
+                    └────────────────────────────┘", output);
+
+			Application.End (rs);
+		}
 	}
 }