Prevent accidental selection move (#848)

master
pmkrawczyk 2022-11-27 10:28:55 +01:00 committed by GitHub
parent 1cd30205d9
commit c0d0db4d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -24,6 +24,7 @@ const {
} = hstry } = hstry
let svgCanvas = null let svgCanvas = null
let moveSelectionThresholdReached = false
/** /**
* @function module:undo.init * @function module:undo.init
@ -155,7 +156,13 @@ const mouseMoveEvent = (evt) => {
dy = snapToGrid(dy) 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) => { selectedElements.forEach((el) => {
if (el) { if (el) {
updateTransformList(svgRoot, el, dx, dy) updateTransformList(svgRoot, el, dx, dy)
@ -563,6 +570,7 @@ const mouseOutEvent = () => {
* @returns {void} * @returns {void}
*/ */
const mouseUpEvent = (evt) => { const mouseUpEvent = (evt) => {
moveSelectionThresholdReached = false
if (evt.button === 2) { return } if (evt.button === 2) { return }
if (!svgCanvas.getStarted()) { return } if (!svgCanvas.getStarted()) { return }