Explorar o código

Merge pull request #2417 from BDisp/v2_single-smaller-top-fix_2416

Fixes #2416. Single smaller top level leaves chunk trails on move.
Tig %!s(int64=2) %!d(string=hai) anos
pai
achega
d445ba1aa6
Modificáronse 2 ficheiros con 94 adicións e 0 borrados
  1. 9 0
      Terminal.Gui/Core/Application.cs
  2. 85 0
      UnitTests/TopLevels/ToplevelTests.cs

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

@@ -1163,6 +1163,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 
@@ -1270,6 +1271,14 @@ 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.NeedDisplay.IsEmpty || state.Toplevel.ChildNeedsDisplay || state.Toplevel.LayoutNeeded
 				|| MdiChildNeedsDisplay ()) {
 				state.Toplevel.Redraw (state.Toplevel.Bounds);

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