Prevent accidental selection move (#848)

This commit is contained in:
pmkrawczyk
2022-11-27 10:28:55 +01:00
committed by GitHub
parent 1cd30205d9
commit c0d0db4d7e

View File

@@ -24,6 +24,7 @@ const {
} = hstry
let svgCanvas = null
let moveSelectionThresholdReached = false
/**
* @function module:undo.init
@@ -155,7 +156,13 @@ const mouseMoveEvent = (evt) => {
dy = snapToGrid(dy)
}
if (dx || dy) {
// Enable moving selection only if mouse has been moved at least 4 px in any direction
// This prevents objects from being accidentally moved when (initially) selected
const deltaThreshold = 4
const deltaThresholdReached = Math.abs(dx) > deltaThreshold || Math.abs(dy) > deltaThreshold
moveSelectionThresholdReached = moveSelectionThresholdReached || deltaThresholdReached
if (moveSelectionThresholdReached) {
selectedElements.forEach((el) => {
if (el) {
updateTransformList(svgRoot, el, dx, dy)
@@ -563,6 +570,7 @@ const mouseOutEvent = () => {
* @returns {void}
*/
const mouseUpEvent = (evt) => {
moveSelectionThresholdReached = false
if (evt.button === 2) { return }
if (!svgCanvas.getStarted()) { return }