Skip to content

Commit 2e1723d

Browse files
committed
Fix selection lost after undo / redo
1 parent 0a76b24 commit 2e1723d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseGraphView.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,14 @@ void ReloadView()
604604
// so the one that are not serialized need to be synchronized)
605605
graph.Deserialize();
606606

607+
// Get selected nodes
608+
var selectedNodeGUIDs = new List<string>();
609+
foreach (var e in selection)
610+
{
611+
if (e is BaseNodeView v && this.Contains(v))
612+
selectedNodeGUIDs.Add(v.nodeTarget.GUID);
613+
}
614+
607615
// Remove everything
608616
RemoveNodeViews();
609617
RemoveEdges();
@@ -623,6 +631,15 @@ void ReloadView()
623631
Reload();
624632

625633
UpdateComputeOrder();
634+
635+
// Restore selection after re-creating all views
636+
// selection = nodeViews.Where(v => selectedNodeGUIDs.Contains(v.nodeTarget.GUID)).Select(v => v as ISelectable).ToList();
637+
foreach (var guid in selectedNodeGUIDs)
638+
{
639+
AddToSelection(nodeViews.FirstOrDefault(n => n.nodeTarget.GUID == guid));
640+
}
641+
642+
UpdateNodeInspectorSelection();
626643
}
627644

628645
public void Initialize(BaseGraph graph)

0 commit comments

Comments
 (0)