Skip to content

Commit 20b1988

Browse files
committed
Fix pending connection connecting cross editors #37
1 parent 8af1c6a commit 20b1988

3 files changed

Lines changed: 27 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
#### **In development**
44

5+
> - Breaking Changes:
6+
> - Features:
7+
> - Bugfixes:
8+
9+
#### **Version 4.0.0**
10+
511
> - Breaking Changes:
612
> - Removed Selection field from NodifyEditor
713
> - Removed InitialMousePosition, CurrentMousePosition, PreviousMousePosition fields from NodifyEditor
814
> - Removed ItemContainer.DraggableHost (use Editor.ItemsHost instead)
915
> - Made SelectionType required in SelectionHelper
1016
> - Moved GroupingNode.SwitchMovementModeModifierKey to EditorGestures.GroupingNode
17+
> - Pending connections are now restricted to connect only to Connectors or to NodifyEditors and ItemContainers if PendingConnection.AllowOnlyConnectors is false
1118
> - Features:
1219
> - Added Connector.EnableStickyConnections to allow completing pending connections in two steps.
1320
> - Added editor states which can be overriden by inheriting from NodifyEditor and implementing NodifyEditor.GetInitialState().
@@ -28,6 +35,7 @@
2835
> - Fixed HandleRightClickAfterPanningThreshold not working as expected
2936
> - Fixed DisablePanning not disabling auto panning in certain situations
3037
> - Fixed GroupingNode selection not working with multiple selection modes
38+
> - Fixed PendingConnection connecting cross editors
3139
3240
#### **Version 3.0.0**
3341

Nodify/Connections/Connector.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static Connector()
121121
/// <summary>
122122
/// Gets the <see cref="NodifyEditor"/> that owns this <see cref="Container"/>.
123123
/// </summary>
124-
protected NodifyEditor? Editor { get; private set; }
124+
protected internal NodifyEditor? Editor { get; private set; }
125125

126126
/// <summary>
127127
/// Gets or sets the safe zone outside the editor's viewport that will not trigger optimizations.
@@ -428,17 +428,11 @@ protected virtual void OnConnectorDragCompleted(bool cancel = false)
428428
{
429429
if (IsPendingConnection)
430430
{
431-
FrameworkElement? elem = null;
432-
if (Editor != null)
433-
{
434-
elem = PendingConnection.GetPotentialConnector(Editor, PendingConnection.GetAllowOnlyConnectorsAttached(Editor));
435-
}
436-
437-
object? target = elem?.DataContext;
431+
FrameworkElement? elem = Editor != null ? PendingConnection.GetPotentialConnector(Editor, PendingConnection.GetAllowOnlyConnectorsAttached(Editor)) : null;
438432

439433
var args = new PendingConnectionEventArgs(DataContext)
440434
{
441-
TargetConnector = target,
435+
TargetConnector = elem?.DataContext,
442436
RoutedEvent = PendingConnectionCompletedEvent,
443437
Anchor = Anchor,
444438
Source = this,

Nodify/Connections/PendingConnection.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected virtual void OnPendingConnectionDrag(object sender, PendingConnectionE
276276
if (Editor != null && (EnablePreview || EnableSnapping))
277277
{
278278
// Look for a potential connector
279-
FrameworkElement? connector = GetPotentialConnector(Editor.ItemsHost, AllowOnlyConnectors);
279+
FrameworkElement? connector = GetPotentialConnector(Editor, AllowOnlyConnectors);
280280

281281
// Update the connector's anchor and snap to it if snapping is enabled
282282
if (EnableSnapping && connector is Connector target)
@@ -341,22 +341,24 @@ protected virtual void OnPendingConnectionCompleted(object sender, PendingConnec
341341

342342
#region Helpers
343343

344-
/// <summary>
345-
/// Searches for a potential connector prioritizing <see cref="Connector"/>s
346-
/// </summary>
347-
/// <param name="container">The container to scan</param>
348-
/// <param name="allowOnlyConnectors">Will also look for <see cref="ItemContainer"/>s if false then for <see cref="FrameworkElement"/>s</param>
349-
/// <returns>The connector if found</returns>
350-
internal static FrameworkElement? GetPotentialConnector(FrameworkElement container, bool allowOnlyConnectors)
344+
/// <summary>Searches for a potential connector prioritizing <see cref="Connector"/>s</summary>
345+
/// <param name="editor">The editor to scan for connectors or item containers.</param>
346+
/// <param name="allowOnlyConnectors">Will also look for <see cref="ItemContainer"/>s if false.</param>
347+
/// <returns>A connector, an item container, the editor or null.</returns>
348+
internal static FrameworkElement? GetPotentialConnector(NodifyEditor editor, bool allowOnlyConnectors)
351349
{
352-
FrameworkElement? connector = container.GetElementUnderMouse<Connector>();
350+
Connector? connector = editor.ItemsHost.GetElementUnderMouse<Connector>();
351+
if (connector != null && connector.Editor == editor)
352+
return connector;
353353

354-
if (connector == null && !allowOnlyConnectors)
355-
{
356-
connector = container.GetElementUnderMouse<ItemContainer>() ?? container.GetElementUnderMouse<FrameworkElement>();
357-
}
354+
if (allowOnlyConnectors)
355+
return null;
356+
357+
var itemContainer = editor.ItemsHost.GetElementUnderMouse<ItemContainer>();
358+
if (itemContainer != null && itemContainer.Editor == editor)
359+
return itemContainer;
358360

359-
return connector;
361+
return editor;
360362
}
361363

362364
#endregion

0 commit comments

Comments
 (0)