Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/blockly/core/dragging/block_drag_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,11 +1142,15 @@ export class BlockDragStrategy implements IDragStrategy {
const actualPosition = this.block.getRelativeToSurfaceXY();
const delta = Coordinate.difference(newLocation, actualPosition);
const {x, y} = delta;

if (x < 0) return Direction.LEFT;
if (x > 0) return Direction.RIGHT;
if (y < 0) return Direction.UP;
if (y > 0) return Direction.DOWN;
// Pick the dominant axis rather than testing x before y. A keyboard move is
// single-axis by intent, but the delta is round-tripped through pixels
// (KeyboardMover scales up by workspace.scale, Dragger scales back down), so
// at any zoom != 1 the axis that should be zero carries ~1e-14 of
// floating-point residue. Comparing magnitudes keeps that residue from
// outranking the real movement and flipping e.g. a DOWN press to RIGHT.
if (Math.abs(x) > Math.abs(y))
return x < 0 ? Direction.LEFT : Direction.RIGHT;
if (Math.abs(y) > 0) return y < 0 ? Direction.UP : Direction.DOWN;
return Direction.NONE;
}

Expand Down
Loading