refactor(core,nodes): move velocity logic into useUpdateNodePositions

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-25 17:38:56 +01:00
committed by Braks
parent 48c4f0a0eb
commit 4260e3158f
2 changed files with 22 additions and 14 deletions
@@ -208,16 +208,15 @@ const onKeyDown = (event: KeyboardEvent) => {
$$(ariaLiveMessage).value = `Moved selected node ${event.key.replace('Arrow', '').toLowerCase()}. New position, x: ${~~node
.position.x}, y: ${~~node.position.y}`
// by default a node moves 5px on each key press, or 20px if shift is pressed
// if snap grid is enabled, we use that for the velocity.
const xVelo = props.snapGrid ? props.snapGrid[0] : 5
const yVelo = props.snapGrid ? props.snapGrid[1] : 5
const factor = event.shiftKey ? 4 : 1
updateNodePositions({
x: arrowKeyDiffs[event.key].x * xVelo * factor,
y: arrowKeyDiffs[event.key].y * yVelo * factor,
})
updateNodePositions(
{
x: arrowKeyDiffs[event.key].x,
y: arrowKeyDiffs[event.key].y,
},
!!props.snapGrid,
props.snapGrid,
event.shiftKey,
)
}
}
</script>