fix: add deletion to the history after backspace is pressed (#310)
* fix: add deletion to the history after BACKSPACE is pressed * Add updateBoundShapes too * fix bug on deleting bound shapes Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
parent
6e72b78e91
commit
d5d999e86d
3 changed files with 12 additions and 7 deletions
|
@ -29,6 +29,9 @@ export function getBoundHandlePoint(
|
||||||
// If the other handle is also bound to a shape, use that other shape's center instead
|
// If the other handle is also bound to a shape, use that other shape's center instead
|
||||||
// of the handle's actual point
|
// of the handle's actual point
|
||||||
const otherToShape = data.page.shapes[oppositeBinding.toId]
|
const otherToShape = data.page.shapes[oppositeBinding.toId]
|
||||||
|
|
||||||
|
if (!otherToShape) return
|
||||||
|
|
||||||
oppositePoint = getShapeUtils(otherToShape).getCenter(otherToShape)
|
oppositePoint = getShapeUtils(otherToShape).getCenter(otherToShape)
|
||||||
} else {
|
} else {
|
||||||
oppositePoint = Vec.add(fromShape.point, oppositeHandle.point)
|
oppositePoint = Vec.add(fromShape.point, oppositeHandle.point)
|
||||||
|
|
|
@ -27,6 +27,7 @@ export const updateBoundShapes: Action = (data) => {
|
||||||
const boundHandle = fromShape.handles[binding.handleId]
|
const boundHandle = fromShape.handles[binding.handleId]
|
||||||
const intersection = getBoundHandlePoint(data, fromShape, toShape, boundHandle.id)
|
const intersection = getBoundHandlePoint(data, fromShape, toShape, boundHandle.id)
|
||||||
|
|
||||||
|
if (intersection) {
|
||||||
if (!Vec.isEqual(boundHandle.point, intersection)) {
|
if (!Vec.isEqual(boundHandle.point, intersection)) {
|
||||||
boundHandle.point = Vec.sub(intersection, fromShape.point)
|
boundHandle.point = Vec.sub(intersection, fromShape.point)
|
||||||
const handles = Object.values(fromShape.handles)
|
const handles = Object.values(fromShape.handles)
|
||||||
|
@ -35,6 +36,7 @@ export const updateBoundShapes: Action = (data) => {
|
||||||
handles.forEach((handle) => (handle.point = Vec.sub(handle.point, offset)))
|
handles.forEach((handle) => (handle.point = Vec.sub(handle.point, offset)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bindingsToDelete.forEach((binding) => delete data.page.bindings[binding.id])
|
bindingsToDelete.forEach((binding) => delete data.page.bindings[binding.id])
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ export const machine = createState({
|
||||||
SELECTED_ALL: 'selectAllShapes',
|
SELECTED_ALL: 'selectAllShapes',
|
||||||
DESELECTED_ALL: 'deselectAllShapes',
|
DESELECTED_ALL: 'deselectAllShapes',
|
||||||
CANCELLED: ['deselectAllShapes', 'updateBoundShapes'],
|
CANCELLED: ['deselectAllShapes', 'updateBoundShapes'],
|
||||||
DELETED: ['deleteSelectedShapes', 'updateBoundShapes'],
|
DELETED: ['deleteSelectedShapes', 'updateBoundShapes', 'addToHistory'],
|
||||||
UNDO: 'undo',
|
UNDO: 'undo',
|
||||||
REDO: 'redo',
|
REDO: 'redo',
|
||||||
HOVERED_SHAPE: 'setHoveredShape',
|
HOVERED_SHAPE: 'setHoveredShape',
|
||||||
|
|
Loading…
Reference in a new issue