Skip to content

Commit

Permalink
Using mask check instead of HasFlag method.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Mar 14, 2024
1 parent e08e873 commit 1724e71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2894,8 +2894,8 @@ public virtual bool OnMouseEvent (MouseEvent mouseEvent)
return false;
}

if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
|| mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)) {
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)) {
Expand Down
12 changes: 7 additions & 5 deletions UnitTests/Views/ViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4582,16 +4582,18 @@ public void View_Instance_Use_Attribute_Normal_On_Draw ()
000000", new Attribute [] { Colors.TopLevel.Normal, Colors.TopLevel.Focus });
}

[Fact]
public void OnMouseClick_Is_Only_Raised_Once ()
[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 = MouseFlags.Button1Pressed });
view.OnMouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Released });
view.OnMouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
view.OnMouseEvent (new MouseEvent () { Flags = pressed });
view.OnMouseEvent (new MouseEvent () { Flags = released });
view.OnMouseEvent (new MouseEvent () { Flags = clicked });

Assert.Equal (1, mouseClicks);
}
Expand Down

0 comments on commit 1724e71

Please sign in to comment.