Steve Ruiz 3 年之前
父節點
當前提交
f15ba31095
共有 1 個文件被更改,包括 14 次插入3 次删除
  1. 14
    3
      examples/core-example-advanced/src/state/actions/erase/eraseShapesAtPoint.ts

+ 14
- 3
examples/core-example-advanced/src/state/actions/erase/eraseShapesAtPoint.ts 查看文件

1
 import type { Action } from 'state/constants'
1
 import type { Action } from 'state/constants'
2
-import type { TLPointerInfo } from '@tldraw/core'
3
-import { getPagePoint } from 'state/helpers'
4
 import { getShapeUtils } from 'shapes'
2
 import { getShapeUtils } from 'shapes'
5
 import { mutables } from 'state/mutables'
3
 import { mutables } from 'state/mutables'
6
 
4
 
7
-export const eraseShapesAtPoint: Action = (data, payload: TLPointerInfo) => {
5
+export const eraseShapesAtPoint: Action = (data) => {
8
   const { currentPoint } = mutables
6
   const { currentPoint } = mutables
9
 
7
 
10
   Object.values(data.page.shapes).forEach((shape) => {
8
   Object.values(data.page.shapes).forEach((shape) => {
12
       delete data.page.shapes[shape.id]
10
       delete data.page.shapes[shape.id]
13
     }
11
     }
14
   })
12
   })
13
+
14
+  const { shapes } = data.page
15
+  const { selectedIds, hoveredId } = data.pageState
16
+
17
+  // Filter out any deleted shapes
18
+  data.pageState.selectedIds = selectedIds.filter((id) => {
19
+    return shapes[id] !== undefined
20
+  })
21
+
22
+  // Remove hovered id if it's been deleted
23
+  if (hoveredId && !shapes[hoveredId]) {
24
+    data.pageState.hoveredId = undefined
25
+  }
15
 }
26
 }

Loading…
取消
儲存