Skip to content

Commit

Permalink
Allow dragging item containers without mouse capture
Browse files Browse the repository at this point in the history
  • Loading branch information
miroiu committed Jan 14, 2025
1 parent 13f75c2 commit bc01626
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
> - Bugfixes:
> - Fixed an issue where connections would not gain focus when selected, which could prevent editor keybindings from functioning in certain scenarios
> - Resolved an issue where selecting a node did not deselect connections and vice versa
> - Fixed a bug preventing ItemContainers from being dragged when the mouse could not be captured
#### **Version 7.0.0**

Expand Down
27 changes: 5 additions & 22 deletions Nodify/Containers/States/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public override void Enter(IInputElementState? from)

protected override void OnMouseDown(MouseButtonEventArgs e)
{
if (!IsSelectable(e))
if (!Element.IsSelectableLocation(e.GetPosition(Element)))
{
return;
}

EditorGestures.ItemContainerGestures gestures = EditorGestures.Mappings.ItemContainer;
if (gestures.Drag.Matches(e.Source, e))
{
_isDragging = Element.IsDraggable && CaptureMouseSafe();
_isDragging = Element.IsDraggable;
}

if (gestures.Selection.Select.Matches(e.Source, e))
Expand All @@ -63,8 +63,8 @@ protected override void OnMouseDown(MouseButtonEventArgs e)

if (_isDragging || _selectionType.HasValue)
{
Element.Focus();
e.Handled = true;
CaptureMouseSafe();
}
}

Expand Down Expand Up @@ -107,31 +107,14 @@ protected override void OnMouseUp(MouseButtonEventArgs e)
_selectionType = null;
}

private bool IsSelectable(MouseButtonEventArgs e)
{
if (!Element.IsSelectableLocation(e.GetPosition(Element)))
{
return false;
}

if (Mouse.Captured != null && !Element.IsMouseCaptured)
{
return false;
}

return true;
}

private bool CaptureMouseSafe()
private void CaptureMouseSafe()
{
// Avoid stealing mouse capture from other elements
if (Mouse.Captured == null || Element.IsMouseCaptured)
{
Element.Focus();
Element.CaptureMouse();
return true;
}

return false;
}

private static SelectionType GetSelectionTypeForDragging(SelectionType? selectionType)
Expand Down

0 comments on commit bc01626

Please sign in to comment.