fix: guard crosshair move handler against re-entrant recursion from applyOptions
This commit is contained in:
parent
0ba3592679
commit
148fe22cd7
1 changed files with 34 additions and 27 deletions
|
|
@ -976,7 +976,9 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
|
|||
if (!drawingState && !dragState) return;
|
||||
if (drawingState && !previewPrimitiveRef.current) return;
|
||||
|
||||
let isUpdating = false;
|
||||
const handleCrosshairMove = (param: any) => {
|
||||
if (isUpdating) return;
|
||||
if (!param.point) return;
|
||||
|
||||
const time = chartRef.current!.timeScale().coordinateToTime(param.point.x);
|
||||
|
|
@ -986,36 +988,41 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
|
|||
|
||||
const currentPoint = { time, price };
|
||||
|
||||
// Update preview primitive endpoint during drawing
|
||||
if (drawingState && previewPrimitiveRef.current) {
|
||||
if (previewPrimitiveRef.current instanceof TrendLine) {
|
||||
previewPrimitiveRef.current.updatePoints(
|
||||
drawingState.firstPoint as Point,
|
||||
currentPoint as Point
|
||||
);
|
||||
} else if (previewPrimitiveRef.current instanceof RectangleDrawingPrimitive) {
|
||||
previewPrimitiveRef.current.updatePoints(
|
||||
drawingState.firstPoint as RectanglePoint,
|
||||
currentPoint as RectanglePoint
|
||||
);
|
||||
}
|
||||
seriesRef.current!.applyOptions({});
|
||||
}
|
||||
|
||||
// Update line endpoint during dragging
|
||||
if (dragState) {
|
||||
const linePrimitive = linePrimitivesRef.current.get(dragState.lineId);
|
||||
if (linePrimitive) {
|
||||
const p1 = linePrimitive.getP1();
|
||||
const p2 = linePrimitive.getP2();
|
||||
|
||||
if (dragState.endpoint === 'p1') {
|
||||
linePrimitive.updatePoints(currentPoint as Point, p2);
|
||||
} else {
|
||||
linePrimitive.updatePoints(p1, currentPoint as Point);
|
||||
isUpdating = true;
|
||||
try {
|
||||
// Update preview primitive endpoint during drawing
|
||||
if (drawingState && previewPrimitiveRef.current) {
|
||||
if (previewPrimitiveRef.current instanceof TrendLine) {
|
||||
previewPrimitiveRef.current.updatePoints(
|
||||
drawingState.firstPoint as Point,
|
||||
currentPoint as Point
|
||||
);
|
||||
} else if (previewPrimitiveRef.current instanceof RectangleDrawingPrimitive) {
|
||||
previewPrimitiveRef.current.updatePoints(
|
||||
drawingState.firstPoint as RectanglePoint,
|
||||
currentPoint as RectanglePoint
|
||||
);
|
||||
}
|
||||
seriesRef.current!.applyOptions({});
|
||||
}
|
||||
|
||||
// Update line endpoint during dragging
|
||||
if (dragState) {
|
||||
const linePrimitive = linePrimitivesRef.current.get(dragState.lineId);
|
||||
if (linePrimitive) {
|
||||
const p1 = linePrimitive.getP1();
|
||||
const p2 = linePrimitive.getP2();
|
||||
|
||||
if (dragState.endpoint === 'p1') {
|
||||
linePrimitive.updatePoints(currentPoint as Point, p2);
|
||||
} else {
|
||||
linePrimitive.updatePoints(p1, currentPoint as Point);
|
||||
}
|
||||
seriesRef.current!.applyOptions({});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
isUpdating = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue