Skip to content

Commit

Permalink
Merge pull request gui-cs#3320 from BDisp/v1_mouseclick-fix_3318
Browse files Browse the repository at this point in the history
Fixes gui-cs#3318. v1-MouseClick should be invoked only once on a mouse click.
  • Loading branch information
tig authored Mar 16, 2024
2 parents deb601e + 1724e71 commit 26c06d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions UnitTests/Views/ViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 26c06d7

Please sign in to comment.