fix(preview): Ctrl+right no longer opens the menu, and the social bar keeps its click
Two event-pairing bugs found by validating every handler instead of trusting the table. 1. Ctrl+right-click opened the context menu in edit mode. Cause: WPF's PopupControlService opens menus on right-button-UP, and only the DOWN event was being handled — so the zoom toggled and the menu appeared under it. Both events are now handled when Ctrl is down. (The creator saw this in edit mode; preview mode had the same latent bug.) 2. The social bar's left-click was dead in preview mode and dragged the layer beneath it in edit mode. Cause: PreviewGrid handles the TUNNELLING PreviewMouseLeftButtonDown, which fires before the bar's bubbling handler — and since preview-mode left-click now toggles zoom, that handler swallowed the bar's click too. The preview handler now steps aside when the point is inside the bar's bounds (SocialBarElement.RenderSize, translated to canvas). Audited and left alone because they are correct: left-down → resize handle / element drag / deselect; move → zoom drag before edit drag (by design); left-up → EndPreviewDrag; right-up → zoom-drag release then the Ctrl swallow. Build Debug 0 warnings, 22 tests pass across ZoomBox, PreviewHistory and SocialBar.
This commit is contained in:
@@ -402,6 +402,18 @@ public partial class PreviewPane : UserControl
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>Is this canvas point inside the social bar? It is a full-width strip at the top or
|
||||
/// bottom of the frame and it consumes its own click, so the preview's tunnelling handler has
|
||||
/// to step aside (see <c>Preview_MouseLeftButtonDown</c>).</summary>
|
||||
private bool IsOverSocialBar(Point canvasPoint)
|
||||
{
|
||||
if (DataContext is not MainViewModel { SocialBarVisible: true }) return false;
|
||||
if (SocialBarElement.ActualHeight <= 0) return false;
|
||||
|
||||
var topLeft = SocialBarElement.TranslatePoint(new Point(0, 0), CanvasGrid);
|
||||
return new Rect(topLeft, SocialBarElement.RenderSize).Contains(canvasPoint);
|
||||
}
|
||||
|
||||
private void SocialsButton_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (SocialBarElement == null) return;
|
||||
@@ -453,6 +465,16 @@ public partial class PreviewPane : UserControl
|
||||
var vm = DataContext as MainViewModel;
|
||||
if (vm is null) return;
|
||||
|
||||
var grid = (Grid)sender;
|
||||
var toCanvas = CanvasGrid.TransformToVisual(grid).Inverse;
|
||||
var p = toCanvas.Transform(e.GetPosition(grid));
|
||||
|
||||
// The social bar owns its own left-click (toggle top ⇄ bottom). This handler is the
|
||||
// TUNNELLING preview event, so it fires before the bar's bubbling handler: without this
|
||||
// guard the bar would be unclickable in preview mode (zoom would win) and, in edit mode,
|
||||
// it would drag whatever layer sat underneath it.
|
||||
if (IsOverSocialBar(p)) return;
|
||||
|
||||
// Preview mode (EDIT off): the left button drives the zoom box — the common gesture in
|
||||
// the mode where nothing is editable. Dragging it afterwards is handled by MouseMove.
|
||||
if (!vm.IsEditMode)
|
||||
@@ -461,10 +483,6 @@ public partial class PreviewPane : UserControl
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var grid = (Grid)sender;
|
||||
var toCanvas = CanvasGrid.TransformToVisual(grid).Inverse;
|
||||
var p = toCanvas.Transform(e.GetPosition(grid));
|
||||
var selected = vm.SelectedElement;
|
||||
|
||||
if (selected is { } sel && IsDraggableElement(sel) && HitHandle(e.GetPosition(grid), sel))
|
||||
@@ -603,7 +621,9 @@ public partial class PreviewPane : UserControl
|
||||
|
||||
vm.ToggleZoom();
|
||||
e.Handled = true;
|
||||
} private void Preview_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||
}
|
||||
|
||||
private void Preview_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (_isZoomDragging)
|
||||
{
|
||||
@@ -614,6 +634,13 @@ public partial class PreviewPane : UserControl
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// WPF's PopupControlService opens a context menu on right-button-UP, not down — so
|
||||
// handling the Down event alone still let a menu appear under a Ctrl+right-click (found
|
||||
// by the creator in edit mode, 2026-11-01). Swallow the Up event too, in both modes:
|
||||
// Down decides the action, Up must not undo that decision.
|
||||
if ((Keyboard.Modifiers & ModifierKeys.Control) != 0)
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void EndPreviewDrag(Grid grid)
|
||||
|
||||
Reference in New Issue
Block a user