Bugfix: Ensure the focus range doesn't invert upon snapping

This commit is contained in:
Aria Minaei 2022-05-03 12:42:53 +02:00
parent 3ecc3dd012
commit 6caf8267c5

View file

@ -204,6 +204,24 @@ const FocusRangeThumb: React.FC<{
let newPosition: number
const oldPosPlusDeltaPos = posBeforeDrag + deltaPos
// Enable snapping
const snapTarget = event
.composedPath()
.find(
(el): el is Element =>
el instanceof Element &&
el !== hitZoneNode &&
el.hasAttribute('data-pos'),
)
if (snapTarget) {
const snapPos = parseFloat(snapTarget.getAttribute('data-pos')!)
if (isFinite(snapPos)) {
newPosition = snapPos
}
}
// Make sure that the focus range has a minimal width
if (thumbType === 'start') {
// Prevent the start thumb from going below 0
@ -225,24 +243,6 @@ const FocusRangeThumb: React.FC<{
)
}
// Enable snapping
const snapTarget = event
.composedPath()
.find(
(el): el is Element =>
el instanceof Element &&
el !== hitZoneNode &&
el.hasAttribute('data-pos'),
)
if (snapTarget) {
const snapPos = parseFloat(snapTarget.getAttribute('data-pos')!)
if (isFinite(snapPos)) {
newPosition = snapPos
}
}
const newPositionInFrame = sheet
.getSequence()
.closestGridPosition(newPosition)