From 391de7fd0abeb5e5b3f9b9330e0f075c3c27c77d Mon Sep 17 00:00:00 2001 From: zhangheng Date: Fri, 3 Apr 2026 21:08:50 +0800 Subject: [PATCH] fix(tools): cross --- components/label/components/CrosshairComponent.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/label/components/CrosshairComponent.tsx b/components/label/components/CrosshairComponent.tsx index 68d960e..e569746 100644 --- a/components/label/components/CrosshairComponent.tsx +++ b/components/label/components/CrosshairComponent.tsx @@ -21,6 +21,7 @@ const CrosshairComponent = ( const { scale } = useTopToolsStore() const canvasRef = useRef(null) + const lastPointerRef = useRef<{ x: number; y: number } | null>(null) const getFixed = (sparsity: number) => { const pointIdx = String(sparsity).indexOf(".") @@ -76,6 +77,7 @@ const CrosshairComponent = ( ctx.beginPath() ctx.setLineDash([]) ctx.strokeStyle = "#EF4444" + ctx.fillStyle = "#EF4444" let carveLineWidth = 1 ctx.lineWidth = carveLineWidth @@ -100,6 +102,7 @@ const CrosshairComponent = ( sparsity ).toFixed(fixed) const textWidth = ctx.measureText(text).width + ctx.fillStyle = "#EF4444" ctx.fillText(text, indexX - textWidth / 2, centerY - tickLength) } else { ctx.moveTo(indexX, centerY - tickLength / 2 - carveLineWidth) @@ -143,7 +146,11 @@ const CrosshairComponent = ( canvas.width = window.innerWidth canvas.height = window.innerHeight const rect = canvas.getBoundingClientRect() - drawCrosshair(rect.width / 2, rect.height / 2) + const center = lastPointerRef.current || { + x: rect.width / 2, + y: rect.height / 2, + } + drawCrosshair(center.x, center.y) } }, [drawCrosshair]) @@ -153,6 +160,7 @@ const CrosshairComponent = ( const rect = canvas.getBoundingClientRect() const centerX = event.clientX - rect.left const centerY = event.clientY - rect.top + lastPointerRef.current = { x: centerX, y: centerY } drawCrosshair(centerX, centerY) } }