Skip to content

Commit c122d53

Browse files
feat: use direction for unconstrained moves
1 parent eddf103 commit c122d53

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/actions/mover.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export class Mover {
118118
{
119119
name: 'Move left, unconstrained',
120120
preconditionFn: (workspace) => this.isMoving(workspace),
121-
callback: (workspace) => this.moveUnconstrained(workspace, -1, 0),
121+
callback: (workspace) =>
122+
this.moveUnconstrained(workspace, Direction.Left),
122123
keyCodes: [
123124
createSerializedKey(KeyCodes.LEFT, [KeyCodes.ALT]),
124125
createSerializedKey(KeyCodes.LEFT, [KeyCodes.CTRL]),
@@ -127,7 +128,8 @@ export class Mover {
127128
{
128129
name: 'Move right, unconstrained',
129130
preconditionFn: (workspace) => this.isMoving(workspace),
130-
callback: (workspace) => this.moveUnconstrained(workspace, 1, 0),
131+
callback: (workspace) =>
132+
this.moveUnconstrained(workspace, Direction.Right),
131133
keyCodes: [
132134
createSerializedKey(KeyCodes.RIGHT, [KeyCodes.ALT]),
133135
createSerializedKey(KeyCodes.RIGHT, [KeyCodes.CTRL]),
@@ -136,7 +138,7 @@ export class Mover {
136138
{
137139
name: 'Move up unconstrained',
138140
preconditionFn: (workspace) => this.isMoving(workspace),
139-
callback: (workspace) => this.moveUnconstrained(workspace, 0, -1),
141+
callback: (workspace) => this.moveUnconstrained(workspace, Direction.Up),
140142
keyCodes: [
141143
createSerializedKey(KeyCodes.UP, [KeyCodes.ALT]),
142144
createSerializedKey(KeyCodes.UP, [KeyCodes.CTRL]),
@@ -145,7 +147,8 @@ export class Mover {
145147
{
146148
name: 'Move down, unconstrained',
147149
preconditionFn: (workspace) => this.isMoving(workspace),
148-
callback: (workspace) => this.moveUnconstrained(workspace, 0, 1),
150+
callback: (workspace) =>
151+
this.moveUnconstrained(workspace, Direction.Down),
149152
keyCodes: [
150153
createSerializedKey(KeyCodes.DOWN, [KeyCodes.ALT]),
151154
createSerializedKey(KeyCodes.DOWN, [KeyCodes.CTRL]),
@@ -341,23 +344,17 @@ export class Mover {
341344
* without constraint.
342345
*
343346
* @param workspace The workspace to move on.
344-
* @param xDirection -1 to move left. 1 to move right.
345-
* @param yDirection -1 to move up. 1 to move down.
347+
* @param direction The direction to move the dragged item.
346348
* @returns True iff this action applies and has been performed.
347349
*/
348-
moveUnconstrained(
349-
workspace: WorkspaceSvg,
350-
xDirection: number,
351-
yDirection: number,
352-
): boolean {
350+
moveUnconstrained(workspace: WorkspaceSvg, direction: Direction): boolean {
353351
if (!workspace) return false;
354352
const info = this.moves.get(workspace);
355353
if (!info) throw new Error('no move info for workspace');
356354

357-
info.totalDelta.x +=
358-
xDirection * UNCONSTRAINED_MOVE_DISTANCE * workspace.scale;
359-
info.totalDelta.y +=
360-
yDirection * UNCONSTRAINED_MOVE_DISTANCE * workspace.scale;
355+
const {x, y} = getXYFromDirection(direction);
356+
info.totalDelta.x += x * UNCONSTRAINED_MOVE_DISTANCE * workspace.scale;
357+
info.totalDelta.y += y * UNCONSTRAINED_MOVE_DISTANCE * workspace.scale;
361358

362359
info.dragger.onDrag(info.fakePointerEvent('pointermove'), info.totalDelta);
363360
return true;

0 commit comments

Comments
 (0)