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.

direct.ts 945B

12345678910111213141516171819202122232425262728293031323334353637
  1. import Command from './command'
  2. import history from '../history'
  3. import { DirectionSnapshot } from 'state/sessions/direction-session'
  4. import { Data, LineShape, RayShape } from 'types'
  5. import { getPage } from 'utils/utils'
  6. export default function directCommand(
  7. data: Data,
  8. before: DirectionSnapshot,
  9. after: DirectionSnapshot
  10. ): void {
  11. history.execute(
  12. data,
  13. new Command({
  14. name: 'set_direction',
  15. category: 'canvas',
  16. do(data) {
  17. const { shapes } = getPage(data)
  18. for (const { id, direction } of after.shapes) {
  19. const shape = shapes[id] as RayShape | LineShape
  20. shape.direction = direction
  21. }
  22. },
  23. undo(data) {
  24. const { shapes } = getPage(data, before.currentPageId)
  25. for (const { id, direction } of after.shapes) {
  26. const shape = shapes[id] as RayShape | LineShape
  27. shape.direction = direction
  28. }
  29. },
  30. })
  31. )
  32. }