diff --git a/CHANGELOG.md b/CHANGELOG.md
index af51655c..eab470de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
> - Features:
> - 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
#### **Version 7.0.0**
diff --git a/Nodify/Connections/ConnectionsMultiSelector.cs b/Nodify/Connections/ConnectionsMultiSelector.cs
index b8d17f8f..05969bfb 100644
--- a/Nodify/Connections/ConnectionsMultiSelector.cs
+++ b/Nodify/Connections/ConnectionsMultiSelector.cs
@@ -44,6 +44,11 @@ private bool CanSelectMultipleItemsBase
set => base.CanSelectMultipleItems = value;
}
+ ///
+ /// Gets the that owns this .
+ ///
+ public NodifyEditor? Editor { get; private set; }
+
protected override DependencyObject GetContainerForItemOverride()
=> new ConnectionContainer(this);
@@ -66,6 +71,15 @@ public void Select(ConnectionContainer container)
#endif
EndUpdateSelectedItems();
+
+ Editor?.UnselectAll();
+ }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ Editor = this.GetParentOfType();
}
#region Selection Handlers
diff --git a/Nodify/Editor/NodifyEditor.Selecting.cs b/Nodify/Editor/NodifyEditor.Selecting.cs
index ac894f9e..ffd53e87 100644
--- a/Nodify/Editor/NodifyEditor.Selecting.cs
+++ b/Nodify/Editor/NodifyEditor.Selecting.cs
@@ -292,6 +292,8 @@ public void Select(ItemContainer container)
selected.Clear();
selected.Add(container.DataContext);
EndUpdateSelectedItems();
+
+ UnselectAllConnections();
}
///
@@ -360,7 +362,6 @@ public void BeginSelecting(Point location, SelectionType type = SelectionType.Re
return;
}
- UnselectAllConnections();
SelectedArea = _selection.Start(ItemContainers, location, type, EnableRealtimeSelection);
IsSelecting = true;
}
@@ -396,6 +397,11 @@ public void EndSelecting()
return;
}
+ if (_selection.Type == SelectionType.Replace)
+ {
+ UnselectAllConnections();
+ }
+
SelectedArea = _selection.End();
ApplyPreviewingSelection();
IsSelecting = false;
@@ -416,7 +422,7 @@ public void CancelSelecting()
if (IsSelecting)
{
- ClearPreviewingSelection();
+ _selection.Cancel();
IsSelecting = false;
}
}
@@ -443,16 +449,6 @@ private void ApplyPreviewingSelection()
EndUpdateSelectedItems();
}
- private void ClearPreviewingSelection()
- {
- ItemCollection items = Items;
- for (var i = 0; i < items.Count; i++)
- {
- var container = (ItemContainer)ItemContainerGenerator.ContainerFromIndex(i);
- container.IsPreviewingSelection = null;
- }
- }
-
#endregion
#region Selection Handlers
diff --git a/Nodify/Utilities/SelectionHelper.cs b/Nodify/Utilities/SelectionHelper.cs
index b9cecc8b..02a611de 100644
--- a/Nodify/Utilities/SelectionHelper.cs
+++ b/Nodify/Utilities/SelectionHelper.cs
@@ -14,12 +14,13 @@ internal sealed class SelectionHelper
{
private Point _startLocation;
private Point _endLocation;
- private SelectionType _selectionType;
private bool _isRealtime;
- private IReadOnlyCollection _items = Array.Empty();
+ private IReadOnlyList _items = Array.Empty();
private IReadOnlyList _initialSelection = Array.Empty();
private Rect _selectedArea;
+ public SelectionType Type { get; private set; }
+
/// Attempts to start a new selection.
/// The containers that can be part of the selection.
/// The location inside the graph.
@@ -30,7 +31,7 @@ public Rect Start(IEnumerable containers, Point location, Selecti
_items = containers.Where(x => x.IsSelectable).ToList();
_initialSelection = containers.Where(x => x.IsSelected).ToList();
- _selectionType = selectionType;
+ Type = selectionType;
_isRealtime = realtime;
_startLocation = location;
@@ -79,9 +80,18 @@ public Rect End()
return _selectedArea;
}
+ public void Cancel()
+ {
+ ClearPreviewingSelection();
+ _items = Array.Empty();
+ _initialSelection = Array.Empty();
+ }
+
+ #region Selection preview
+
private void PreviewSelection(Rect area)
{
- switch (_selectionType)
+ switch (Type)
{
case SelectionType.Replace:
PreviewSelectArea(area);
@@ -114,9 +124,9 @@ private void PreviewSelection(Rect area)
private void PreviewUnselectAll()
{
- foreach (var container in _items)
+ for (int i = 0; i < _items.Count; i++)
{
- container.IsPreviewingSelection = false;
+ _items[i].IsPreviewingSelection = false;
}
}
@@ -129,8 +139,9 @@ private void PreviewSelectArea(Rect area, bool append = false, bool fit = false)
if (area.X != 0 || area.Y != 0 || area.Width > 0 || area.Height > 0)
{
- foreach (var container in _items)
+ for (int i = 0; i < _items.Count; i++)
{
+ ItemContainer? container = _items[i];
if (container.IsSelectableInArea(area, fit))
{
container.IsPreviewingSelection = true;
@@ -141,8 +152,9 @@ private void PreviewSelectArea(Rect area, bool append = false, bool fit = false)
private void PreviewUnselectArea(Rect area, bool fit = false)
{
- foreach (var container in _items)
+ for (int i = 0; i < _items.Count; i++)
{
+ ItemContainer? container = _items[i];
if (container.IsSelectableInArea(area, fit))
{
container.IsPreviewingSelection = false;
@@ -152,7 +164,7 @@ private void PreviewUnselectArea(Rect area, bool fit = false)
private static void PreviewSelectContainers(IReadOnlyList containers)
{
- for (var i = 0; i < containers.Count; i++)
+ for (int i = 0; i < containers.Count; i++)
{
containers[i].IsPreviewingSelection = true;
}
@@ -160,14 +172,25 @@ private static void PreviewSelectContainers(IReadOnlyList contain
private void PreviewInvertSelection(Rect area, bool fit = false)
{
- foreach (var container in _items)
+ for (int i = 0; i < _items.Count; i++)
{
+ ItemContainer? container = _items[i];
if (container.IsSelectableInArea(area, fit))
{
container.IsPreviewingSelection = !container.IsPreviewingSelection;
}
}
}
+
+ private void ClearPreviewingSelection()
+ {
+ for (int i = 0; i < _items.Count; i++)
+ {
+ _items[i].IsPreviewingSelection = null;
+ }
+ }
+
+ #endregion
}
internal static class SelectionGesturesExtensions