Render focus point in debug mode

This commit is contained in:
Mark Tolmacs
2025-08-25 16:57:32 +02:00
parent 0c39ace058
commit d1688deda7
2 changed files with 46 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ import {
getNormalizedCanvasDimensions, getNormalizedCanvasDimensions,
} from "@excalidraw/excalidraw/renderer/helpers"; } from "@excalidraw/excalidraw/renderer/helpers";
import { type AppState } from "@excalidraw/excalidraw/types"; import { type AppState } from "@excalidraw/excalidraw/types";
import { arrayToMap, invariant, throttleRAF } from "@excalidraw/common"; import { arrayToMap, throttleRAF } from "@excalidraw/common";
import { useCallback } from "react"; import { useCallback } from "react";
import { import {
@@ -181,12 +181,13 @@ const renderBindings = (
if (isArrowElement(element)) { if (isArrowElement(element)) {
if (element.startBinding) { if (element.startBinding) {
invariant( if (
elementsMap !elementsMap
.get(element.startBinding.elementId) .get(element.startBinding.elementId)
?.boundElements?.find((e) => e.id === element.id), ?.boundElements?.find((e) => e.id === element.id)
"Missing record in boundElements for arrow", ) {
); return;
}
_renderBinding( _renderBinding(
context, context,
@@ -200,6 +201,13 @@ const renderBindings = (
} }
if (element.endBinding) { if (element.endBinding) {
if (
!elementsMap
.get(element.endBinding.elementId)
?.boundElements?.find((e) => e.id === element.id)
) {
return;
}
_renderBinding( _renderBinding(
context, context,
element.endBinding, element.endBinding,

View File

@@ -1,8 +1,10 @@
import { import {
KEYS, KEYS,
arrayToMap, arrayToMap,
debugDrawPoint,
invariant, invariant,
isAlwaysInsideBinding, isAlwaysInsideBinding,
isDevEnv,
tupleToCoors, tupleToCoors,
} from "@excalidraw/common"; } from "@excalidraw/common";
@@ -588,7 +590,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
// Handle new arrow creation separately, as it is special // Handle new arrow creation separately, as it is special
if (opts?.newArrow) { if (opts?.newArrow) {
return bindingStrategyForNewSimpleArrowEndpointDragging( const { start, end } = bindingStrategyForNewSimpleArrowEndpointDragging(
arrow, arrow,
draggingPoints, draggingPoints,
elementsMap, elementsMap,
@@ -600,6 +602,17 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
appState, appState,
globalBindMode, globalBindMode,
); );
if (isDevEnv()) {
if (start?.focusPoint) {
debugDrawPoint(start.focusPoint);
}
if (end?.focusPoint) {
debugDrawPoint(end.focusPoint);
}
}
return { start, end };
} }
// Only the start point is dragged // Only the start point is dragged
@@ -621,6 +634,15 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
{ appState }, { appState },
); );
if (isDevEnv()) {
if (current?.focusPoint) {
debugDrawPoint(current.focusPoint);
}
if (other?.focusPoint) {
debugDrawPoint(other.focusPoint);
}
}
return { start: current, end: other }; return { start: current, end: other };
} }
@@ -642,6 +664,15 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
{ appState }, { appState },
); );
if (isDevEnv()) {
if (current?.focusPoint) {
debugDrawPoint(current.focusPoint);
}
if (other?.focusPoint) {
debugDrawPoint(other.focusPoint);
}
}
return { start: other, end: current }; return { start: other, end: current };
} }