Browse Source

Broke OnMouseClicked

Tig 9 months ago
parent
commit
9363401f44

+ 0 - 3
Terminal.Gui/Application/Application.Mouse.cs

@@ -170,9 +170,6 @@ public static partial class Application // Mouse handling
             return;
         }
 
-        // We can combine this into the switch expression to reduce cognitive complexity even more and likely
-        // avoid one or two of these checks in the process, as well.
-
         WantContinuousButtonPressedView = deepestViewUnderMouse switch
         {
             { WantContinuousButtonPressed: true } => deepestViewUnderMouse,

+ 19 - 0
Terminal.Gui/Input/MouseEventArgs.cs

@@ -26,6 +26,25 @@ public class MouseEventArgs : HandledEventArgs
     /// <summary>The position of the mouse in <see cref="View"/>'s Viewport-relative coordinates. Only valid if <see cref="View"/> is set.</summary>
     public Point Position { get; set; }
 
+    public bool IsButtonEvent
+    {
+        get
+        {
+            return  Flags.HasFlag (MouseFlags.Button1Clicked)
+                   || Flags.HasFlag (MouseFlags.Button2Clicked)
+                   || Flags.HasFlag (MouseFlags.Button3Clicked)
+                   || Flags.HasFlag (MouseFlags.Button4Clicked)
+                   || Flags.HasFlag (MouseFlags.Button1DoubleClicked)
+                   || Flags.HasFlag (MouseFlags.Button2DoubleClicked)
+                   || Flags.HasFlag (MouseFlags.Button3DoubleClicked)
+                   || Flags.HasFlag (MouseFlags.Button4DoubleClicked)
+                   || Flags.HasFlag (MouseFlags.Button1TripleClicked)
+                   || Flags.HasFlag (MouseFlags.Button2TripleClicked)
+                   || Flags.HasFlag (MouseFlags.Button3TripleClicked)
+                   || Flags.HasFlag (MouseFlags.Button4TripleClicked);
+        }
+    }
+
     /// <summary>Returns a <see cref="T:System.String"/> that represents the current <see cref="Terminal.Gui.MouseEventArgs"/>.</summary>
     /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="Terminal.Gui.MouseEventArgs"/>.</returns>
     public override string ToString () { return $"({ScreenPosition}):{Flags}:{View?.Id}:{Position}"; }

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

@@ -201,7 +201,7 @@ public partial class View // Mouse APIs
 
     /// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
     /// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
-    public virtual bool WantMousePositionReports { get; set; }
+    public bool WantMousePositionReports { get; set; }
 
     /// <summary>
     ///     Processes a new <see cref="MouseEvent"/>. This method is called by <see cref="Application.RaiseMouseEvent"/> when a mouse
@@ -487,11 +487,9 @@ public partial class View // Mouse APIs
             || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
             || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
         {
-            bool firstPress = true;
             // The first time we get pressed event, grab the mouse and set focus
             if (Application.MouseGrabView != this)
             {
-                firstPress = true;
                 Application.GrabMouse (this);
 
                 if (!HasFocus && CanFocus)
@@ -499,6 +497,8 @@ public partial class View // Mouse APIs
                     // Set the focus, but don't invoke Accept
                     SetFocus ();
                 }
+
+                mouseEvent.Handled = true;
             }
 
             if (Viewport.Contains (mouseEvent.Position))
@@ -519,7 +519,7 @@ public partial class View // Mouse APIs
                 }
             }
 
-            if (!firstPress && WantContinuousButtonPressed && Application.MouseGrabView == this)
+            if (WantContinuousButtonPressed && Application.MouseGrabView == this)
             {
                 // If this is not the first pressed event, generate a click
                 return RaiseMouseClickEvent (mouseEvent);