tldraw/state/commands/nudge.ts

36 lines
903 B
TypeScript
Raw Normal View History

2021-05-28 20:30:27 +00:00
import Command from './command'
import history from '../history'
import { Data } from 'types'
2021-06-29 12:00:59 +00:00
import tld from 'utils/tld'
import vec from 'utils/vec'
2021-05-28 20:30:27 +00:00
2021-06-21 21:35:28 +00:00
export default function nudgeCommand(data: Data, delta: number[]): void {
2021-06-29 12:00:59 +00:00
const initialShapes = tld.getSelectedShapeSnapshot(data, () => null)
2021-05-28 20:30:27 +00:00
history.execute(
data,
new Command({
2021-06-19 17:22:46 +00:00
name: 'nudge_shapes',
2021-05-28 20:30:27 +00:00
category: 'canvas',
do(data) {
2021-06-29 12:00:59 +00:00
tld.mutateShapes(
data,
initialShapes.map((shape) => shape.id),
(shape, utils) => {
utils.setProperty(shape, 'point', vec.add(shape.point, delta))
}
)
2021-05-28 20:30:27 +00:00
},
undo(data) {
2021-06-29 12:00:59 +00:00
tld.mutateShapes(
data,
initialShapes.map((shape) => shape.id),
(shape, utils) => {
utils.setProperty(shape, 'point', vec.sub(shape.point, delta))
}
)
2021-05-28 20:30:27 +00:00
},
})
)
}