fix(core advance example): fix the error, when erase the shape (#398)

This commit is contained in:
Yao Wang 2021-11-27 22:51:17 +08:00 committed by GitHub
parent 4e148590cb
commit dbbdb764ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,8 @@
import type { Action } from 'state/constants' import type { Action } from 'state/constants'
import type { TLPointerInfo } from '@tldraw/core'
import { getPagePoint } from 'state/helpers'
import { getShapeUtils } from 'shapes' import { getShapeUtils } from 'shapes'
import { mutables } from 'state/mutables' import { mutables } from 'state/mutables'
export const eraseShapesAtPoint: Action = (data, payload: TLPointerInfo) => { export const eraseShapesAtPoint: Action = (data) => {
const { currentPoint } = mutables const { currentPoint } = mutables
Object.values(data.page.shapes).forEach((shape) => { Object.values(data.page.shapes).forEach((shape) => {
@ -12,4 +10,17 @@ export const eraseShapesAtPoint: Action = (data, payload: TLPointerInfo) => {
delete data.page.shapes[shape.id] 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
}
} }