diff --git a/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMath.cs b/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMath.cs
index 9d00458..ad49763 100644
--- a/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMath.cs
+++ b/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMath.cs
@@ -3,7 +3,7 @@ namespace Ghost.Editor.Core.Controls.Internal.Docking;
///
/// Defines the possible dock positions for a drop operation.
///
-public enum DockPosition
+internal enum DockPosition
{
Center,
Top,
@@ -16,7 +16,7 @@ public enum DockPosition
///
/// Helper class for docking-related calculations.
///
-public static class DockMath
+internal static class DockMath
{
///
/// Calculates the dock position based on the relative position within a target element.
diff --git a/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMutationEngine.cs b/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMutationEngine.cs
index 60328c6..7f83416 100644
--- a/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMutationEngine.cs
+++ b/src/Editor/Ghost.Editor.Core/Controls/Internal/Docking/DockMutationEngine.cs
@@ -1,4 +1,3 @@
-using Ghost.Editor.Core.Controls.Internal.Docking;
using Microsoft.UI.Xaml.Controls;
namespace Ghost.Editor.Core.Controls.Internal.Docking;
@@ -6,7 +5,7 @@ namespace Ghost.Editor.Core.Controls.Internal.Docking;
///
/// Provides methods for mutating the docking layout tree.
///
-public static class DockMutationEngine
+internal static class DockMutationEngine
{
///
/// Applies the tree mutation for a drop operation.
@@ -14,6 +13,14 @@ public static class DockMutationEngine
/// True if the mutation was applied; otherwise, false.
public static bool TryApplyDropMutation(DockGroupNode root, DockPanelNode targetNode, DockPanelNode sourceNode, object item, DockPosition position)
{
+ if (position == DockPosition.None) return false;
+
+ // Validate ancestry
+ if (!IsDescendantOf(root, targetNode) || !IsDescendantOf(root, sourceNode))
+ {
+ return false;
+ }
+
if (position == DockPosition.Center)
{
if (!sourceNode.Items.Remove(item)) return false;
@@ -139,4 +146,15 @@ public static class DockMutationEngine
}
}
}
+
+ private static bool IsDescendantOf(DockGroupNode root, DockNode node)
+ {
+ var current = node.Parent;
+ while (current != null)
+ {
+ if (ReferenceEquals(current, root)) return true;
+ current = current.Parent;
+ }
+ return false;
+ }
}