You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nudge.ts 903B

1234567891011121314151617181920212223242526272829303132333435
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data } from 'types'
  4. import tld from 'utils/tld'
  5. import vec from 'utils/vec'
  6. export default function nudgeCommand(data: Data, delta: number[]): void {
  7. const initialShapes = tld.getSelectedShapeSnapshot(data, () => null)
  8. history.execute(
  9. data,
  10. new Command({
  11. name: 'nudge_shapes',
  12. category: 'canvas',
  13. do(data) {
  14. tld.mutateShapes(
  15. data,
  16. initialShapes.map((shape) => shape.id),
  17. (shape, utils) => {
  18. utils.setProperty(shape, 'point', vec.add(shape.point, delta))
  19. }
  20. )
  21. },
  22. undo(data) {
  23. tld.mutateShapes(
  24. data,
  25. initialShapes.map((shape) => shape.id),
  26. (shape, utils) => {
  27. utils.setProperty(shape, 'point', vec.sub(shape.point, delta))
  28. }
  29. )
  30. },
  31. })
  32. )
  33. }