fix(dock): improve mutation engine safety and revert public surface expansion

This commit is contained in:
2026-03-28 15:07:39 +09:00
parent 5efd0c8aee
commit 419552439d
2 changed files with 22 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ namespace Ghost.Editor.Core.Controls.Internal.Docking;
/// <summary> /// <summary>
/// Defines the possible dock positions for a drop operation. /// Defines the possible dock positions for a drop operation.
/// </summary> /// </summary>
public enum DockPosition internal enum DockPosition
{ {
Center, Center,
Top, Top,
@@ -16,7 +16,7 @@ public enum DockPosition
/// <summary> /// <summary>
/// Helper class for docking-related calculations. /// Helper class for docking-related calculations.
/// </summary> /// </summary>
public static class DockMath internal static class DockMath
{ {
/// <summary> /// <summary>
/// Calculates the dock position based on the relative position within a target element. /// Calculates the dock position based on the relative position within a target element.

View File

@@ -1,4 +1,3 @@
using Ghost.Editor.Core.Controls.Internal.Docking;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
namespace Ghost.Editor.Core.Controls.Internal.Docking; namespace Ghost.Editor.Core.Controls.Internal.Docking;
@@ -6,7 +5,7 @@ namespace Ghost.Editor.Core.Controls.Internal.Docking;
/// <summary> /// <summary>
/// Provides methods for mutating the docking layout tree. /// Provides methods for mutating the docking layout tree.
/// </summary> /// </summary>
public static class DockMutationEngine internal static class DockMutationEngine
{ {
/// <summary> /// <summary>
/// Applies the tree mutation for a drop operation. /// Applies the tree mutation for a drop operation.
@@ -14,6 +13,14 @@ public static class DockMutationEngine
/// <returns>True if the mutation was applied; otherwise, false.</returns> /// <returns>True if the mutation was applied; otherwise, false.</returns>
public static bool TryApplyDropMutation(DockGroupNode root, DockPanelNode targetNode, DockPanelNode sourceNode, object item, DockPosition position) 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 (position == DockPosition.Center)
{ {
if (!sourceNode.Items.Remove(item)) return false; 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;
}
} }