diff --git a/examples/core-example-advanced/src/state/actions/erase/eraseShapesAtPoint.ts b/examples/core-example-advanced/src/state/actions/erase/eraseShapesAtPoint.ts index 23c536cb1..91f9f6e58 100644 --- a/examples/core-example-advanced/src/state/actions/erase/eraseShapesAtPoint.ts +++ b/examples/core-example-advanced/src/state/actions/erase/eraseShapesAtPoint.ts @@ -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 + } }