fix point pos

This commit is contained in:
Joeri Exelmans 2025-10-09 13:21:36 +02:00
parent 09a87d3025
commit 131f82c5db

View file

@ -152,9 +152,16 @@ export function VisualEditor({ast, setAST, rt, setRT, errors, setErrors}: Visual
return () => clearTimeout(timeout); return () => clearTimeout(timeout);
}, [state]); }, [state]);
function getCurrentPointer(e: MouseEvent) {
const bbox = refSVG.current!.getBoundingClientRect();
return {
x: e.pageX - bbox.left,
y: e.pageY - bbox.top,
}
}
const onMouseDown: MouseEventHandler<SVGSVGElement> = (e) => { const onMouseDown: MouseEventHandler<SVGSVGElement> = (e) => {
const currentPointer = {x: e.pageX, y: e.pageY}; const currentPointer = getCurrentPointer(e);
if (e.button === 1) { if (e.button === 1) {
checkPoint(); checkPoint();
@ -240,7 +247,7 @@ export function VisualEditor({ast, setAST, rt, setRT, errors, setErrors}: Visual
}; };
const onMouseMove = (e: MouseEvent) => { const onMouseMove = (e: MouseEvent) => {
const currentPointer = {x: e.pageX, y: e.pageY}; const currentPointer = getCurrentPointer(e);
if (dragging) { if (dragging) {
const pointerDelta = subtractV2D(currentPointer, dragging.lastMousePos); const pointerDelta = subtractV2D(currentPointer, dragging.lastMousePos);
setState(state => ({ setState(state => ({