Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3318. v1-MouseClick should be invoked only once on a mouse click. #3320

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading