Skip to content

Commit 9096c6e

Browse files
Copilotargyleink
andauthored
Fix radial gradient centerpoint drag drift (#126)
* Initial plan * Fix gradient centerpoint drag drift by correcting pixel-to-percentage conversion Co-authored-by: argyleink <1134620+argyleink@users.noreply.github.com> * Revert changes to RadialOverlay and ConicOverlay drag calculations Co-authored-by: argyleink <1134620+argyleink@users.noreply.github.com> * Restore improved radial gradient position drag calculation Co-authored-by: argyleink <1134620+argyleink@users.noreply.github.com> * Fix radial gradient position drag drift using absolute cursor positioning Co-authored-by: argyleink <1134620+argyleink@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: argyleink <1134620+argyleink@users.noreply.github.com>
1 parent 947a619 commit 9096c6e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/components/RadialOverlay.svelte

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,16 @@
316316
}
317317
}
318318
else if (dragulaState.moving) {
319-
let wpercent = (size.w / 2) / 100
320-
let hpercent = (size.h / 2) / 100
321-
dragulaState.left += e.movementX / wpercent
322-
dragulaState.top += e.movementY / hpercent
319+
// Use absolute cursor position relative to the preview element
320+
// to avoid drift from accumulated movementX/Y rounding errors
321+
const previewEl = node.closest('.preview')
322+
if (previewEl) {
323+
const rect = previewEl.getBoundingClientRect()
324+
const x = ((e.clientX - rect.left) / rect.width) * 100
325+
const y = ((e.clientY - rect.top) / rect.height) * 100
326+
dragulaState.left = x
327+
dragulaState.top = y
328+
}
323329
324330
$radial_position.x = Math.round(dragulaState.left)
325331
$radial_position.y = Math.round(dragulaState.top)

0 commit comments

Comments
 (0)