diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 174abd94bc..c89d433d26 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -2894,9 +2894,14 @@ public virtual bool OnMouseEvent (MouseEvent mouseEvent) return false; } - var args = new MouseEventArgs (mouseEvent); - if (OnMouseClick (args)) - return true; + if ((mouseEvent.Flags & MouseFlags.Button1Clicked) != 0 || (mouseEvent.Flags & MouseFlags.Button2Clicked) != 0 + || (mouseEvent.Flags & MouseFlags.Button3Clicked) != 0 || (mouseEvent.Flags & MouseFlags.Button4Clicked) != 0) { + + var args = new MouseEventArgs (mouseEvent); + if (OnMouseClick (args)) { + return true; + } + } if (MouseEvent (mouseEvent)) return true; diff --git a/UnitTests/Views/ViewTests.cs b/UnitTests/Views/ViewTests.cs index 2f161d9065..dc366989db 100644 --- a/UnitTests/Views/ViewTests.cs +++ b/UnitTests/Views/ViewTests.cs @@ -4581,5 +4581,21 @@ public void View_Instance_Use_Attribute_Normal_On_Draw () 011110 000000", new Attribute [] { Colors.TopLevel.Normal, Colors.TopLevel.Focus }); } + + [Theory] + [InlineData (MouseFlags.Button1Pressed, MouseFlags.Button1Released, MouseFlags.Button1Clicked)] + [InlineData (MouseFlags.Button1Pressed | MouseFlags.ButtonCtrl, MouseFlags.Button1Released | MouseFlags.ButtonCtrl, MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl)] + public void OnMouseClick_Is_Only_Raised_Once (MouseFlags pressed, MouseFlags released, MouseFlags clicked) + { + var mouseClicks = 0; + var view = new View (); + view.MouseClick += (_) => mouseClicks++; + + view.OnMouseEvent (new MouseEvent () { Flags = pressed }); + view.OnMouseEvent (new MouseEvent () { Flags = released }); + view.OnMouseEvent (new MouseEvent () { Flags = clicked }); + + Assert.Equal (1, mouseClicks); + } } }