Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

delete-selected.ts 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Command from "./command"
  2. import history from "../history"
  3. import { TranslateSnapshot } from "state/sessions/translate-session"
  4. import { Data } from "types"
  5. import { getPage } from "utils/utils"
  6. import { current } from "immer"
  7. export default function deleteSelected(data: Data) {
  8. const { currentPageId } = data
  9. const selectedIds = Array.from(data.selectedIds.values())
  10. const page = getPage(current(data))
  11. const shapes = selectedIds.map((id) => page.shapes[id])
  12. data.selectedIds.clear()
  13. history.execute(
  14. data,
  15. new Command({
  16. name: "delete_shapes",
  17. category: "canvas",
  18. manualSelection: true,
  19. do(data) {
  20. const page = getPage(data, currentPageId)
  21. for (let id of selectedIds) {
  22. delete page.shapes[id]
  23. }
  24. data.selectedIds.clear()
  25. },
  26. undo(data) {
  27. const page = getPage(data, currentPageId)
  28. data.selectedIds.clear()
  29. for (let shape of shapes) {
  30. page.shapes[shape.id] = shape
  31. data.selectedIds.add(shape.id)
  32. }
  33. },
  34. })
  35. )
  36. }