Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

delete-shapes.ts 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import Command from './command'
  2. import history from '../history'
  3. import { Data, Shape } from 'types'
  4. import tld from 'utils/tld'
  5. export default function deleteShapes(data: Data, shapes: Shape[]): void {
  6. const initialSelectedIds = [...tld.getSelectedIds(data)]
  7. const shapeIdsToDelete = shapes.flatMap((shape) =>
  8. shape.isLocked ? [] : tld.getDocumentBranch(data, shape.id)
  9. )
  10. const remainingIds = initialSelectedIds.filter(
  11. (id) => !shapeIdsToDelete.includes(id)
  12. )
  13. // We're going to delete the shapes and their children, too; and possibly
  14. // their parents, if we delete all of a group shape's children.
  15. let deletedShapes: Shape[] = []
  16. history.execute(
  17. data,
  18. new Command({
  19. name: 'delete_selection',
  20. category: 'canvas',
  21. manualSelection: true,
  22. do(data) {
  23. deletedShapes = tld.deleteShapes(data, shapeIdsToDelete)
  24. tld.setSelectedIds(data, remainingIds)
  25. },
  26. undo(data) {
  27. tld.createShapes(data, deletedShapes)
  28. tld.setSelectedIds(data, initialSelectedIds)
  29. },
  30. })
  31. )
  32. }