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>
/// Defines the possible dock positions for a drop operation.
/// </summary>
public enum DockPosition
internal enum DockPosition
{
Center,
Top,
@@ -16,7 +16,7 @@ public enum DockPosition
/// <summary>
/// Helper class for docking-related calculations.
/// </summary>
public static class DockMath
internal static class DockMath
{
/// <summary>
/// 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;
namespace Ghost.Editor.Core.Controls.Internal.Docking;
@@ -6,7 +5,7 @@ namespace Ghost.Editor.Core.Controls.Internal.Docking;
/// <summary>
/// Provides methods for mutating the docking layout tree.
/// </summary>
public static class DockMutationEngine
internal static class DockMutationEngine
{
/// <summary>
/// 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>
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;
}
}