fix(dock): address reviewer feedback on drag state and boundary tests

This commit is contained in:
2026-03-28 14:30:28 +09:00
parent 7d759c8797
commit c2cfd18273
3 changed files with 60 additions and 6 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.
@@ -24,6 +24,12 @@ public static class DockMath
/// </summary>
public static DockPosition CalculateDockPosition(double width, double height, double x, double y, double threshold)
{
// Guard against invalid inputs
if (width <= 0 || height <= 0) return DockPosition.None;
// Clamp threshold to valid range [0, 0.5]
threshold = Math.Max(0, Math.Min(0.5, threshold));
if (x < width * threshold) return DockPosition.Left;
if (x > width * (1 - threshold)) return DockPosition.Right;
if (y < height * threshold) return DockPosition.Top;