fix(core advance example): fix the error, when erase the shape (#398)
This commit is contained in:
parent
4e148590cb
commit
dbbdb764ab
1 changed files with 14 additions and 3 deletions
|
@ -1,10 +1,8 @@
|
|||
import type { Action } from 'state/constants'
|
||||
import type { TLPointerInfo } from '@tldraw/core'
|
||||
import { getPagePoint } from 'state/helpers'
|
||||
import { getShapeUtils } from 'shapes'
|
||||
import { mutables } from 'state/mutables'
|
||||
|
||||
export const eraseShapesAtPoint: Action = (data, payload: TLPointerInfo) => {
|
||||
export const eraseShapesAtPoint: Action = (data) => {
|
||||
const { currentPoint } = mutables
|
||||
|
||||
Object.values(data.page.shapes).forEach((shape) => {
|
||||
|
@ -12,4 +10,17 @@ export const eraseShapesAtPoint: Action = (data, payload: TLPointerInfo) => {
|
|||
delete data.page.shapes[shape.id]
|
||||
}
|
||||
})
|
||||
|
||||
const { shapes } = data.page
|
||||
const { selectedIds, hoveredId } = data.pageState
|
||||
|
||||
// Filter out any deleted shapes
|
||||
data.pageState.selectedIds = selectedIds.filter((id) => {
|
||||
return shapes[id] !== undefined
|
||||
})
|
||||
|
||||
// Remove hovered id if it's been deleted
|
||||
if (hoveredId && !shapes[hoveredId]) {
|
||||
data.pageState.hoveredId = undefined
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue