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;

View File

@@ -324,16 +324,21 @@ public sealed partial class DockLayout : Control
private void TabView_DragLeave(object sender, DragEventArgs e)
{
ClearDragState();
ClearOverlayState();
}
private void ClearDragState()
private void ClearOverlayState()
{
if (_dropTargetOverlay != null)
{
_dropTargetOverlay.Visibility = Visibility.Collapsed;
}
_currentDropPosition = DockPosition.None;
}
private void ClearDragOperationState()
{
ClearOverlayState();
_draggedItem = null;
_sourceNode = null;
}
@@ -374,10 +379,9 @@ public sealed partial class DockLayout : Control
}
}
// Add a dummy TabView_Drop method so it compiles, we will implement it in Task 6
private void TabView_Drop(object sender, DragEventArgs e)
{
ClearDragState();
ClearDragOperationState();
}
protected override void OnApplyTemplate()