Skip to content

Commit

Permalink
Fix jump when dragging from a drag handle. Fixes #502
Browse files Browse the repository at this point in the history
  • Loading branch information
sekoyo committed Jul 30, 2022
1 parent 29aef3e commit 7ecd034
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ReactCrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,35 @@ class ReactCrop extends PureComponent<ReactCropProps, ReactCropState> {

// Set the starting coords to the opposite corner.
if (ord) {
const relativeX = e.clientX - box.x
const relativeY = e.clientY - box.y
let fromCornerX = 0
let fromCornerY = 0

if (ord === 'ne' || ord == 'e') {
fromCornerX = relativeX - (pixelCrop.x + pixelCrop.width)
fromCornerY = relativeY - pixelCrop.y
startCropX = pixelCrop.x
startCropY = pixelCrop.y + pixelCrop.height
} else if (ord === 'se' || ord === 's') {
fromCornerX = relativeX - (pixelCrop.x + pixelCrop.width)
fromCornerY = relativeY - (pixelCrop.y + pixelCrop.height)
startCropX = pixelCrop.x
startCropY = pixelCrop.y
} else if (ord === 'sw' || ord == 'w') {
fromCornerX = relativeX - pixelCrop.x
fromCornerY = relativeY - (pixelCrop.y + pixelCrop.height)
startCropX = pixelCrop.x + pixelCrop.width
startCropY = pixelCrop.y
} else if (ord === 'nw' || ord == 'n') {
fromCornerX = relativeX - pixelCrop.x
fromCornerY = relativeY - pixelCrop.y
startCropX = pixelCrop.x + pixelCrop.width
startCropY = pixelCrop.y + pixelCrop.height
}
startClientX = startCropX + box.x
startClientY = startCropY + box.y

startClientX = startCropX + box.x + fromCornerX
startClientY = startCropY + box.y + fromCornerY
}

this.evData = {
Expand Down

0 comments on commit 7ecd034

Please sign in to comment.