Fix error where arrows with bindings could not be deleted

pull/71/head
Steve Ruiz 2021-08-30 11:59:31 +01:00
rodzic b7902f3ce8
commit e98edef97d
2 zmienionych plików z 11 dodań i 3 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ import type { Data, TLDrawCommand, PagePartial } from '~types'
// - [x] Delete shapes
// - [x] Delete bindings too
// - [ ] Delete bound shapes (arrows)
// - [ ] Update parents and possibly delete parents
export function deleteShapes(data: Data, ids: string[]): TLDrawCommand {
@ -38,15 +39,17 @@ export function deleteShapes(data: Data, ids: string[]): TLDrawCommand {
// Let's also look at the bound shape...
const shape = TLDR.getShape(data, id, currentPageId)
// If the bound shape has a handle that references the deleted binding, delete that reference
// If the bound shape has a handle that references the deleted binding...
if (shape.handles) {
Object.values(shape.handles)
.filter((handle) => handle.bindingId === binding.id)
.filter((handle) => handle.bindingId === binding.id && after.shapes[id] !== undefined)
.forEach((handle) => {
// Otherwise, delete the reference to the deleted binding
before.shapes[id] = {
...before.shapes[id],
handles: { ...before.shapes[id]?.handles, [handle.id]: { bindingId: binding.id } },
}
after.shapes[id] = {
...after.shapes[id],
handles: { ...after.shapes[id]?.handles, [handle.id]: { bindingId: undefined } },

Wyświetl plik

@ -298,7 +298,7 @@ export class TLDrawState extends StateManager<Data> {
return this.patchState(
{
appState: {
isToolLocked: true,
isToolLocked: !this.appState.isToolLocked,
},
},
`toggled_tool_lock`
@ -845,6 +845,11 @@ export class TLDrawState extends StateManager<Data> {
},
}
if (this.appState.isToolLocked) {
const pageState = result.after?.document?.pageStates?.[this.currentPageId] || {}
pageState.selectedIds = []
}
this.isCreating = false
}