Snapping now works in selections too
This commit is contained in:
parent
e2e6754de1
commit
4eaba1e8d5
6 changed files with 36 additions and 27 deletions
|
@ -172,20 +172,23 @@ function useDragKeyframe(node: HTMLDivElement | null, props: IProps) {
|
||||||
return {
|
return {
|
||||||
lockCursorTo: 'ew-resize',
|
lockCursorTo: 'ew-resize',
|
||||||
onDragStart(event) {
|
onDragStart(event) {
|
||||||
if (propsRef.current.selection) {
|
const props = propsRef.current
|
||||||
const {selection, leaf} = propsRef.current
|
if (props.selection) {
|
||||||
|
const {selection, leaf} = props
|
||||||
const {sheetObject} = leaf
|
const {sheetObject} = leaf
|
||||||
selectionDragHandlers = selection.getDragHandlers({
|
selectionDragHandlers = selection.getDragHandlers({
|
||||||
...sheetObject.address,
|
...sheetObject.address,
|
||||||
pathToProp: leaf.pathToProp,
|
pathToProp: leaf.pathToProp,
|
||||||
trackId: leaf.trackId,
|
trackId: leaf.trackId,
|
||||||
keyframeId: propsRef.current.keyframe.id,
|
keyframeId: props.keyframe.id,
|
||||||
|
positionAtStartOfDrag:
|
||||||
|
props.trackData.keyframes[props.index].position,
|
||||||
})
|
})
|
||||||
selectionDragHandlers.onDragStart?.(event)
|
selectionDragHandlers.onDragStart?.(event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
propsAtStartOfDrag = propsRef.current
|
propsAtStartOfDrag = props
|
||||||
sequence = val(propsAtStartOfDrag.layoutP.sheet).getSequence()
|
sequence = val(propsAtStartOfDrag.layoutP.sheet).getSequence()
|
||||||
|
|
||||||
toUnitSpace = val(propsAtStartOfDrag.layoutP.scaledSpace.toUnitSpace)
|
toUnitSpace = val(propsAtStartOfDrag.layoutP.scaledSpace.toUnitSpace)
|
||||||
|
|
|
@ -155,20 +155,23 @@ function useDragKeyframe(
|
||||||
return {
|
return {
|
||||||
onDragStart(event) {
|
onDragStart(event) {
|
||||||
setIsDragging(true)
|
setIsDragging(true)
|
||||||
if (propsRef.current.selection) {
|
const props = propsRef.current
|
||||||
const {selection, leaf} = propsRef.current
|
if (props.selection) {
|
||||||
|
const {selection, leaf} = props
|
||||||
const {sheetObject} = leaf
|
const {sheetObject} = leaf
|
||||||
selectionDragHandlers = selection.getDragHandlers({
|
selectionDragHandlers = selection.getDragHandlers({
|
||||||
...sheetObject.address,
|
...sheetObject.address,
|
||||||
pathToProp: leaf.pathToProp,
|
pathToProp: leaf.pathToProp,
|
||||||
trackId: leaf.trackId,
|
trackId: leaf.trackId,
|
||||||
keyframeId: propsRef.current.keyframe.id,
|
keyframeId: props.keyframe.id,
|
||||||
|
positionAtStartOfDrag:
|
||||||
|
props.trackData.keyframes[props.index].position,
|
||||||
})
|
})
|
||||||
selectionDragHandlers.onDragStart?.(event)
|
selectionDragHandlers.onDragStart?.(event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
propsAtStartOfDrag = propsRef.current
|
propsAtStartOfDrag = props
|
||||||
toUnitSpace = val(propsAtStartOfDrag.layoutP.scaledSpace.toUnitSpace)
|
toUnitSpace = val(propsAtStartOfDrag.layoutP.scaledSpace.toUnitSpace)
|
||||||
},
|
},
|
||||||
onDrag(dx, dy, event) {
|
onDrag(dx, dy, event) {
|
||||||
|
|
|
@ -205,12 +205,27 @@ namespace utils {
|
||||||
onDragStart() {
|
onDragStart() {
|
||||||
toUnitSpace = val(layoutP.scaledSpace.toUnitSpace)
|
toUnitSpace = val(layoutP.scaledSpace.toUnitSpace)
|
||||||
},
|
},
|
||||||
onDrag(dx) {
|
onDrag(dx, _, event) {
|
||||||
const delta = toUnitSpace(dx)
|
let delta = toUnitSpace(dx)
|
||||||
if (tempTransaction) {
|
if (tempTransaction) {
|
||||||
tempTransaction.discard()
|
tempTransaction.discard()
|
||||||
tempTransaction = undefined
|
tempTransaction = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const snapTarget = event.composedPath().find(
|
||||||
|
(el): el is Element =>
|
||||||
|
el instanceof Element &&
|
||||||
|
// el !== node &&
|
||||||
|
el.hasAttribute('data-pos'),
|
||||||
|
)
|
||||||
|
|
||||||
|
if (snapTarget) {
|
||||||
|
const snapPos = parseFloat(snapTarget.getAttribute('data-pos')!)
|
||||||
|
if (isFinite(snapPos)) {
|
||||||
|
delta = snapPos - origin.positionAtStartOfDrag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tempTransaction = getStudio()!.tempTransaction(({stateEditors}) => {
|
tempTransaction = getStudio()!.tempTransaction(({stateEditors}) => {
|
||||||
const transformKeyframes =
|
const transformKeyframes =
|
||||||
stateEditors.coreByProject.historic.sheetsById.sequence
|
stateEditors.coreByProject.historic.sheetsById.sequence
|
||||||
|
|
|
@ -150,13 +150,6 @@ function useDragKeyframe(
|
||||||
propsAtStartOfDrag.trackData.keyframes[propsAtStartOfDrag.index - 1]
|
propsAtStartOfDrag.trackData.keyframes[propsAtStartOfDrag.index - 1]
|
||||||
|
|
||||||
if (prev && Math.abs(original.value - prev.value) > 0) {
|
if (prev && Math.abs(original.value - prev.value) > 0) {
|
||||||
// cur.handles[1] = preserveLeftHandle(
|
|
||||||
// cur.handles[1],
|
|
||||||
// original.value,
|
|
||||||
// cur.value,
|
|
||||||
// prev.value,
|
|
||||||
// prev.value,
|
|
||||||
// )
|
|
||||||
const newPrev: Keyframe = {...prev, handles: [...prev.handles]}
|
const newPrev: Keyframe = {...prev, handles: [...prev.handles]}
|
||||||
updatedKeyframes.push(newPrev)
|
updatedKeyframes.push(newPrev)
|
||||||
newPrev.handles[3] = preserveRightHandle(
|
newPrev.handles[3] = preserveRightHandle(
|
||||||
|
@ -171,14 +164,6 @@ function useDragKeyframe(
|
||||||
propsAtStartOfDrag.trackData.keyframes[propsAtStartOfDrag.index + 1]
|
propsAtStartOfDrag.trackData.keyframes[propsAtStartOfDrag.index + 1]
|
||||||
|
|
||||||
if (next && Math.abs(original.value - next.value) > 0) {
|
if (next && Math.abs(original.value - next.value) > 0) {
|
||||||
// cur.handles[3] = preserveRightHandle(
|
|
||||||
// cur.handles[3],
|
|
||||||
// original.value,
|
|
||||||
// cur.value,
|
|
||||||
// next.value,
|
|
||||||
// next.value,
|
|
||||||
// )
|
|
||||||
|
|
||||||
const newNext: Keyframe = {...next, handles: [...next.handles]}
|
const newNext: Keyframe = {...next, handles: [...next.handles]}
|
||||||
updatedKeyframes.push(newNext)
|
updatedKeyframes.push(newNext)
|
||||||
newNext.handles[1] = preserveLeftHandle(
|
newNext.handles[1] = preserveLeftHandle(
|
||||||
|
|
|
@ -52,7 +52,11 @@ export type DopeSheetSelection = {
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
getDragHandlers(
|
getDragHandlers(
|
||||||
origin: PropAddress & {trackId: string; keyframeId: string},
|
origin: PropAddress & {
|
||||||
|
trackId: string
|
||||||
|
keyframeId: string
|
||||||
|
positionAtStartOfDrag: number
|
||||||
|
},
|
||||||
): Parameters<typeof useDrag>[1]
|
): Parameters<typeof useDrag>[1]
|
||||||
delete(): void
|
delete(): void
|
||||||
}
|
}
|
||||||
|
|
|
@ -547,7 +547,6 @@ namespace stateEditors {
|
||||||
const track = _getTrack(p)
|
const track = _getTrack(p)
|
||||||
if (!track) return
|
if (!track) return
|
||||||
const initialKeyframes = current(track.keyframes)
|
const initialKeyframes = current(track.keyframes)
|
||||||
// debugger
|
|
||||||
|
|
||||||
const selectedKeyframes = initialKeyframes.filter(
|
const selectedKeyframes = initialKeyframes.filter(
|
||||||
(kf) => p.keyframeIds.indexOf(kf.id) !== -1,
|
(kf) => p.keyframeIds.indexOf(kf.id) !== -1,
|
||||||
|
|
Loading…
Reference in a new issue