mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
This commit is contained in:
@@ -371,11 +371,11 @@ internal class MouseImpl : IMouse
|
||||
Position = frameLoc,
|
||||
Flags = mouseEvent.Flags,
|
||||
ScreenPosition = mouseEvent.ScreenPosition,
|
||||
View = deepestViewUnderMouse ?? MouseGrabView
|
||||
View = MouseGrabView // Always set to the grab view. See Issue #4370
|
||||
};
|
||||
|
||||
//System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}");
|
||||
if (MouseGrabView?.NewMouseEvent (viewRelativeMouseEvent) is true)
|
||||
if (MouseGrabView?.NewMouseEvent (viewRelativeMouseEvent) is true || viewRelativeMouseEvent.IsSingleClicked)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -409,5 +409,55 @@ public class ApplicationMouseTests
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void MouseGrab_EventSentToGrabView_HasCorrectView ()
|
||||
{
|
||||
// BEFORE FIX: viewRelativeMouseEvent.View = deepestViewUnderMouse ?? MouseGrabView (potentially targetView).
|
||||
// AFTER FIX: viewRelativeMouseEvent.View = MouseGrabView (always the grab view).
|
||||
// Test fails before fix (receivedView == targetView), passes after fix (receivedView == grabView).
|
||||
|
||||
var grabView = new View
|
||||
{
|
||||
Id = "grab",
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
var targetView = new View
|
||||
{
|
||||
Id = "target",
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
View? receivedView = null;
|
||||
grabView.MouseEvent += (_, e) => receivedView = e.View;
|
||||
|
||||
var top = new Toplevel { Width = 20, Height = 10 };
|
||||
top.Add (grabView);
|
||||
top.Add (targetView); // deepestViewUnderMouse = targetView
|
||||
Application.Begin (top);
|
||||
|
||||
Application.Mouse.GrabMouse (grabView);
|
||||
Assert.Equal (grabView, Application.Mouse.MouseGrabView);
|
||||
|
||||
Application.RaiseMouseEvent (new MouseEventArgs
|
||||
{
|
||||
ScreenPosition = new (2, 2), // Inside both views
|
||||
Flags = MouseFlags.Button1Clicked
|
||||
});
|
||||
|
||||
// EXPECTED: Event sent to grab view has View == grabView.
|
||||
Assert.Equal (grabView, receivedView);
|
||||
|
||||
Application.Mouse.UngrabMouse ();
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -2513,7 +2513,7 @@ Edit
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact (Skip = "See Issue #4370. Not gonna try to fix menu v1.")]
|
||||
[AutoInitShutdown]
|
||||
public void MouseEvent_Test ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user