From 131f82c5dbd589a1753a6b4a628b27f07aaa1369 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Thu, 9 Oct 2025 13:21:36 +0200 Subject: [PATCH] fix point pos --- src/VisualEditor/VisualEditor.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/VisualEditor/VisualEditor.tsx b/src/VisualEditor/VisualEditor.tsx index 7d41632..61d1e0d 100644 --- a/src/VisualEditor/VisualEditor.tsx +++ b/src/VisualEditor/VisualEditor.tsx @@ -152,9 +152,16 @@ export function VisualEditor({ast, setAST, rt, setRT, errors, setErrors}: Visual return () => clearTimeout(timeout); }, [state]); + function getCurrentPointer(e: MouseEvent) { + const bbox = refSVG.current!.getBoundingClientRect(); + return { + x: e.pageX - bbox.left, + y: e.pageY - bbox.top, + } + } const onMouseDown: MouseEventHandler = (e) => { - const currentPointer = {x: e.pageX, y: e.pageY}; + const currentPointer = getCurrentPointer(e); if (e.button === 1) { checkPoint(); @@ -240,7 +247,7 @@ export function VisualEditor({ast, setAST, rt, setRT, errors, setErrors}: Visual }; const onMouseMove = (e: MouseEvent) => { - const currentPointer = {x: e.pageX, y: e.pageY}; + const currentPointer = getCurrentPointer(e); if (dragging) { const pointerDelta = subtractV2D(currentPointer, dragging.lastMousePos); setState(state => ({