diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs
index 7264321c3..ecc29d74f 100644
--- a/Source/Editor/Surface/VisjectSurface.Input.cs
+++ b/Source/Editor/Surface/VisjectSurface.Input.cs
@@ -115,15 +115,23 @@ namespace FlaxEditor.Surface
var p1 = _rootControl.PointFromParent(ref _leftMouseDownPos);
var p2 = _rootControl.PointFromParent(ref _mousePos);
var selectionRect = Rectangle.FromPoints(p1, p2);
+ var selectionChanged = false;
// Find controls to select
for (int i = 0; i < _rootControl.Children.Count; i++)
{
if (_rootControl.Children[i] is SurfaceControl control)
{
- control.IsSelected = control.IsSelectionIntersecting(ref selectionRect);
+ var select = control.IsSelectionIntersecting(ref selectionRect);
+ if (select != control.IsSelected)
+ {
+ control.IsSelected = select;
+ selectionChanged = true;
+ }
}
}
+ if (selectionChanged)
+ SelectionChanged?.Invoke();
}
private void OnSurfaceControlSpawned(SurfaceControl control)
diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs
index a0dc4a955..675598b16 100644
--- a/Source/Editor/Surface/VisjectSurface.cs
+++ b/Source/Editor/Surface/VisjectSurface.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using FlaxEditor.GUI;
using FlaxEditor.GUI.Drag;
using FlaxEditor.Options;
@@ -600,7 +601,7 @@ namespace FlaxEditor.Surface
bool selectionChanged = false;
for (int i = 0; i < _rootControl.Children.Count; i++)
{
- if (_rootControl.Children[i] is SurfaceControl control)
+ if (_rootControl.Children[i] is SurfaceControl control && control.IsSelected)
{
control.IsSelected = false;
selectionChanged = true;
@@ -652,11 +653,13 @@ namespace FlaxEditor.Surface
/// The controls.
public void Select(IEnumerable controls)
{
+ var newSelection = controls.ToList();
+ var prevSelection = SelectedControls;
+ if (Utils.ArraysEqual(newSelection, prevSelection))
+ return;
ClearSelection();
- foreach (var control in controls)
- {
+ foreach (var control in newSelection)
control.IsSelected = true;
- }
SelectionChanged?.Invoke();
}
@@ -666,6 +669,8 @@ namespace FlaxEditor.Surface
/// The control.
public void Deselect(SurfaceControl control)
{
+ if (!control.IsSelected)
+ return;
control.IsSelected = false;
SelectionChanged?.Invoke();
}
@@ -724,11 +729,8 @@ namespace FlaxEditor.Surface
Context.OnControlDeleted(control);
}
}
-
if (selectionChanged)
- {
SelectionChanged?.Invoke();
- }
if (nodes != null)
{