浏览代码

unit test issue

Tig 10 月之前
父节点
当前提交
cdfc49ece5
共有 4 个文件被更改,包括 22 次插入16 次删除
  1. 2 2
      Terminal.Gui/View/View.Drawing.cs
  2. 12 12
      Terminal.Gui/View/View.Mouse.cs
  3. 2 2
      Terminal.Gui/Views/Button.cs
  4. 6 0
      UnitTests/Views/MenuBarTests.cs

+ 2 - 2
Terminal.Gui/View/View.Drawing.cs

@@ -396,7 +396,7 @@ public partial class View // Drawing APIs
         }
 
         Attribute disabled = new (cs.Disabled.Foreground, cs.Disabled.Background);
-        if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _Hover)
+        if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _hovering)
         {
             disabled = new (disabled.Foreground.GetDarkerColor (), disabled.Background.GetDarkerColor ());
         }
@@ -406,7 +406,7 @@ public partial class View // Drawing APIs
     private Attribute GetColor (Attribute inputAttribute)
     {
         Attribute attr = inputAttribute;
-        if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _Hover)
+        if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _hovering)
         {
             attr = new (attr.Foreground.GetDarkerColor (), attr.Background.GetDarkerColor ());
         }

+ 12 - 12
Terminal.Gui/View/View.Mouse.cs

@@ -126,7 +126,8 @@ public partial class View // Mouse APIs
 
     #region MouseEnterLeave
 
-    private bool _Hover;
+    private bool _hovering;
+    private ColorScheme? _savedNonHoverColorScheme;
 
     /// <summary>
     ///     INTERNAL Called by <see cref="Application.OnMouseEvent"/> when the mouse moves over the View's <see cref="Frame"/>.
@@ -154,7 +155,7 @@ public partial class View // Mouse APIs
 
         MouseEnter?.Invoke (this, eventArgs);
 
-        _Hover = !eventArgs.Cancel;
+        _hovering = !eventArgs.Cancel;
 
         if (eventArgs.Cancel)
         {
@@ -166,9 +167,8 @@ public partial class View // Mouse APIs
             HighlightStyle copy = HighlightStyle;
             HighlightStyle hover = HighlightStyle.Hover;
             CancelEventArgs<HighlightStyle> args = new (ref copy, ref hover);
-            RaiseHighlight (args);
-
-            if (args.Cancel)
+            
+            if (RaiseHighlight (args) || args.Cancel)
             {
                 return args.Cancel;
             }
@@ -180,7 +180,7 @@ public partial class View // Mouse APIs
                 cs = new ();
             }
 
-            _savedNonHighlightColorScheme = cs;
+            _savedNonHoverColorScheme = cs;
 
             ColorScheme = ColorScheme.GetHighlightColorScheme ();
         }
@@ -260,7 +260,7 @@ public partial class View // Mouse APIs
 
         MouseLeave?.Invoke (this, EventArgs.Empty);
 
-        _Hover = false;
+        _hovering = false;
 
         if ((HighlightStyle.HasFlag (HighlightStyle.Hover) || Diagnostics.HasFlag (ViewDiagnosticFlags.Hover)))
         {
@@ -268,8 +268,11 @@ public partial class View // Mouse APIs
             HighlightStyle hover = HighlightStyle.None;
             RaiseHighlight (new (ref copy, ref hover));
 
-            ColorScheme = _savedNonHighlightColorScheme;
-            _savedNonHighlightColorScheme = default;
+            if (_savedNonHoverColorScheme is { })
+            {
+                ColorScheme = _savedNonHoverColorScheme;
+                _savedNonHoverColorScheme = null;
+            }
         }
     }
 
@@ -447,9 +450,6 @@ public partial class View // Mouse APIs
     /// </summary>
     public event EventHandler<CancelEventArgs<HighlightStyle>>? Highlight;
 
-    private ColorScheme _savedNonHighlightColorScheme;
-
-
 
     /// <summary>
     ///     Enables the highlight for the view when the mouse is pressed. Called from OnMouseEvent.

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

@@ -77,7 +77,7 @@ public class Button : View, IDesignable
         ShadowStyle = DefaultShadow;
         HighlightStyle = DefaultHighlightStyle;
     }
-    
+
     private bool _wantContinuousButtonPressed;
 
     /// <inheritdoc />
@@ -169,7 +169,7 @@ public class Button : View, IDesignable
     /// <inheritdoc/>
     protected override void UpdateTextFormatterText ()
     {
-        base.UpdateTextFormatterText();
+        base.UpdateTextFormatterText ();
         if (NoDecorations)
         {
             TextFormatter.Text = Text;

+ 6 - 0
UnitTests/Views/MenuBarTests.cs

@@ -662,6 +662,12 @@ public class MenuBarTests (ITestOutputHelper output)
     {
 
         ((FakeDriver)Application.Driver).SetBufferSize (40, 15);
+        // Override CM
+        Window.DefaultBorderStyle = LineStyle.Single;
+        Dialog.DefaultButtonAlignment = Alignment.Center;
+        Dialog.DefaultBorderStyle = LineStyle.Single;
+        Button.DefaultShadow = ShadowStyle.None;
+
 
         Assert.Equal (new (0, 0, 40, 15), Application.Driver?.Clip);
         TestHelpers.AssertDriverContentsWithFrameAre (@"", output);