浏览代码

Fixes #2133. TreeView: desiredCursorVisibility field is set before the if condition check.

BDisp 2 年之前
父节点
当前提交
04a8395be5
共有 2 个文件被更改,包括 61 次插入36 次删除
  1. 9 8
      Terminal.Gui/Views/TreeView.cs
  2. 52 28
      UnitTests/TreeViewTests.cs

+ 9 - 8
Terminal.Gui/Views/TreeView.cs

@@ -140,12 +140,12 @@ namespace Terminal.Gui {
 		/// <value></value>
 		public MouseFlags? ObjectActivationButton { get; set; } = MouseFlags.Button1DoubleClicked;
 
-		
+
 		/// <summary>
 		/// Delegate for multi colored tree views.  Return the <see cref="ColorScheme"/> to use
 		/// for each passed object or null to use the default.
 		/// </summary>
-		public Func<T,ColorScheme> ColorGetter {get;set;}
+		public Func<T, ColorScheme> ColorGetter { get; set; }
 
 		/// <summary>
 		/// Secondary selected regions of tree when <see cref="MultiSelect"/> is true
@@ -227,14 +227,15 @@ namespace Terminal.Gui {
 		/// Defaults to <see cref="CursorVisibility.Invisible"/>
 		/// </summary>
 		public CursorVisibility DesiredCursorVisibility {
-			get { 
+			get {
 				return MultiSelect ? desiredCursorVisibility : CursorVisibility.Invisible;
 			}
 			set {
-				desiredCursorVisibility = value;
-
-				if (desiredCursorVisibility != value && HasFocus) {
-					Application.Driver.SetCursorVisibility (DesiredCursorVisibility);
+				if (desiredCursorVisibility != value) {
+					desiredCursorVisibility = value;
+					if (HasFocus) {
+						Application.Driver.SetCursorVisibility (DesiredCursorVisibility);
+					}
 				}
 			}
 		}
@@ -626,7 +627,7 @@ namespace Terminal.Gui {
 		/// </summary>
 		/// <param name="toFind"></param>
 		/// <returns></returns>
-		public int? GetObjectRow(T toFind)
+		public int? GetObjectRow (T toFind)
 		{
 			var idx = BuildLineMap ().IndexOf (o => o.Model.Equals (toFind));
 

+ 52 - 28
UnitTests/TreeViewTests.cs

@@ -839,74 +839,98 @@ namespace Terminal.Gui.Views {
 			Assert.Equal (0, tv.GetObjectRow (n2));
 		}
 		[Fact, AutoInitShutdown]
-		public void TestTreeViewColor()
+		public void TestTreeViewColor ()
 		{
-			var tv = new TreeView{Width = 20,Height = 10};
+			var tv = new TreeView { Width = 20, Height = 10 };
 
-			var n1 = new TreeNode("normal");
-			var n1_1 = new TreeNode("pink");
-			var n1_2 = new TreeNode("normal");
-			n1.Children.Add(n1_1);
-			n1.Children.Add(n1_2);
+			var n1 = new TreeNode ("normal");
+			var n1_1 = new TreeNode ("pink");
+			var n1_2 = new TreeNode ("normal");
+			n1.Children.Add (n1_1);
+			n1.Children.Add (n1_2);
 
-			var n2 = new TreeNode("pink");
-			tv.AddObject(n1);
-			tv.AddObject(n2);
-			tv.Expand(n1);
+			var n2 = new TreeNode ("pink");
+			tv.AddObject (n1);
+			tv.AddObject (n2);
+			tv.Expand (n1);
 
-			var pink = new Attribute(Color.Magenta,Color.Black);
-			var hotpink = new Attribute(Color.BrightMagenta,Color.Black);
+			var pink = new Attribute (Color.Magenta, Color.Black);
+			var hotpink = new Attribute (Color.BrightMagenta, Color.Black);
 
-			tv.ColorScheme = new ColorScheme();
-			tv.Redraw(tv.Bounds);
+			tv.ColorScheme = new ColorScheme ();
+			tv.Redraw (tv.Bounds);
 
 			// Normal drawing of the tree view
-			GraphViewTests.AssertDriverContentsAre(
+			GraphViewTests.AssertDriverContentsAre (
 @"├-normal
 │ ├─pink
 │ └─normal
 └─pink
-",output);
+", output);
 			// Should all be the same color
-			GraphViewTests.AssertDriverColorsAre(
+			GraphViewTests.AssertDriverColorsAre (
 @"00000000
 00000000
 0000000000
 000000
 ",
-				new []{tv.ColorScheme.Normal,pink});
+				new [] { tv.ColorScheme.Normal, pink });
 
 			// create a new color scheme
-			var pinkScheme = new ColorScheme
-			{
+			var pinkScheme = new ColorScheme {
 				Normal = pink,
 				Focus = hotpink
 			};
 
 			// and a delegate that uses the pink color scheme 
 			// for nodes "pink"
-			tv.ColorGetter = (n)=> n.Text.Equals("pink") ? pinkScheme : null;
+			tv.ColorGetter = (n) => n.Text.Equals ("pink") ? pinkScheme : null;
 
 			// redraw now that the custom color
 			// delegate is registered
-			tv.Redraw(tv.Bounds);
-	
+			tv.Redraw (tv.Bounds);
+
 			// Same text
-			GraphViewTests.AssertDriverContentsAre(
+			GraphViewTests.AssertDriverContentsAre (
 @"├-normal
 │ ├─pink
 │ └─normal
 └─pink
-",output);
+", output);
 			// but now the item (only not lines) appear
 			// in pink when they are the word "pink"
-			GraphViewTests.AssertDriverColorsAre(
+			GraphViewTests.AssertDriverColorsAre (
 @"00000000
 00001111
 0000000000
 001111
 ",
-				new []{tv.ColorScheme.Normal,pink});
+				new [] { tv.ColorScheme.Normal, pink });
+		}
+
+		[Fact, AutoInitShutdown]
+		public void DesiredCursorVisibility_MultiSelect ()
+		{
+			var tv = new TreeView { Width = 20, Height = 10 };
+
+			var n1 = new TreeNode ("normal");
+			var n2 = new TreeNode ("pink");
+			tv.AddObject (n1);
+			tv.AddObject (n2);
+
+			Application.Top.Add (tv);
+			Application.Begin (Application.Top);
+
+			Assert.True (tv.MultiSelect);
+			Assert.True (tv.HasFocus);
+			Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
+
+			tv.SelectAll ();
+			tv.DesiredCursorVisibility = CursorVisibility.Default;
+			Application.Refresh ();
+			Application.Driver.GetCursorVisibility (out CursorVisibility visibility);
+			Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
+			Assert.Equal (CursorVisibility.Default, visibility);
 		}
 
 		/// <summary>