fix(select): ignore part drags under 3 px

A click to select or find a part often nudged it by a pixel or two. A press
on a part now moves it only once the cursor travels 3 control pixels; the
part then catches up so the grab point stays under the cursor. A click that
never crosses the threshold records no undo entry and skips the cut-off
regeneration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-12-01 22:02:28 -05:00
1 parent daa4543729
commit 039028afc7
2 files changed
+76 -2

No files matched your search

@@ -149,6 +149,53 @@ public class UndoRedoTests
Assert.Equal(0, editor.History.UndoCount);
});
[Fact]
public void AJitterBelowTheDragThresholdLeavesThePartInPlace() => Run(env =>
{
var editor = env.Editor;
var view = editor.PlateView;
editor.PlateManager.LoadAt(0);
view.ZoomToFit();
var part = view.Plate.Parts[0];
var start = part.Location;
var grab = view.PointWorldToControl(part.BoundingBox.Center);
Mouse(view, "OnMouseMove", MouseButtons.None, grab);
Mouse(view, "OnMouseDown", MouseButtons.Left, grab);
Mouse(view, "OnMouseMove", MouseButtons.Left, new Point(grab.X + 1, grab.Y + 1));
Mouse(view, "OnMouseMove", MouseButtons.Left, new Point(grab.X + 2, grab.Y));
Mouse(view, "OnMouseUp", MouseButtons.Left, new Point(grab.X + 2, grab.Y));
Assert.Equal(start, part.Location);
Assert.Single(view.SelectedParts);
Assert.Equal(0, editor.History.UndoCount);
});
[Fact]
public void ADragPastTheThresholdKeepsTheGrabPointUnderTheCursor() => Run(env =>
{
var editor = env.Editor;
var view = editor.PlateView;
editor.PlateManager.LoadAt(0);
view.ZoomToFit();
var part = view.Plate.Parts[0];
var start = part.Location;
var grab = view.PointWorldToControl(part.BoundingBox.Center);
var release = new Point(grab.X + 10, grab.Y);
Mouse(view, "OnMouseMove", MouseButtons.None, grab);
Mouse(view, "OnMouseDown", MouseButtons.Left, grab);
Mouse(view, "OnMouseMove", MouseButtons.Left, new Point(grab.X + 2, grab.Y));
Mouse(view, "OnMouseMove", MouseButtons.Left, release);
Mouse(view, "OnMouseUp", MouseButtons.Left, release);
var expected = view.PointControlToWorld(release) - view.PointControlToWorld(grab);
var moved = part.Location - start;
Assert.Equal(expected.X, moved.X, 6);
Assert.Equal(expected.Y, moved.Y, 6);
Assert.Equal(1, editor.History.UndoCount);
});
[Fact]
public void AScopeLeftIncompleteRollsBack() => Run(env =>
{
+29 -2
View File
@@ -26,6 +26,14 @@ namespace OpenNest.Actions
// Open from the press on a selected part to the release: a drag undoes as one move.
private ChangeScope drag;
// A press on a part moves it only once the cursor travels this far (control pixels),
// so a click to select or find a part never nudges it by a stray pixel.
public const int DragThreshold = 3;
private Point dragStartControl;
private Vector dragStartWorld;
private bool dragMoved;
public ActionSelect(PlateView plateView)
: base(plateView)
{
@@ -78,6 +86,7 @@ namespace OpenNest.Actions
{
var scope = drag;
drag = null;
dragMoved = false;
if (scope == null)
return;
scope.Complete();
@@ -99,7 +108,22 @@ namespace OpenNest.Actions
if (plateView.SelectedParts.Count == 0)
return;
var offset = plateView.CurrentPoint - plateView.LastPoint;
Vector offset;
if (dragMoved || drag == null)
{
offset = plateView.CurrentPoint - plateView.LastPoint;
}
else
{
var dx = e.X - dragStartControl.X;
var dy = e.Y - dragStartControl.Y;
if (dx * dx + dy * dy < DragThreshold * DragThreshold)
return;
// Catch up to the cursor so the grab point stays under it.
dragMoved = true;
offset = plateView.CurrentPoint - dragStartWorld;
}
drag?.MarkChanged();
foreach (var part in plateView.SelectedParts)
@@ -130,6 +154,9 @@ namespace OpenNest.Actions
{
EndDrag();
drag = plateView.BeginChange("Move");
dragStartControl = e.Location;
dragStartWorld = plateView.CurrentPoint;
dragMoved = false;
return;
}
@@ -175,7 +202,7 @@ namespace OpenNest.Actions
plateView.Invalidate();
status = Status.SetFirstPoint;
}
else if (plateView.SelectedParts.Count > 0)
else if (dragMoved && plateView.SelectedParts.Count > 0)
{
// Part drag completed — regenerate cut-off programs
if (plateView.Plate.CutOffs.Count > 0)