fix: Nested shape binding

This commit is contained in:
Mark Tolmacs 2025-09-11 21:58:19 +02:00
parent e5c7a6304e
commit fb3fe09226
No known key found for this signature in database
2 changed files with 14 additions and 5 deletions

View File

@ -309,8 +309,6 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
invariant(otherElement, "Other element must be in the elements map"); invariant(otherElement, "Other element must be in the elements map");
const otherIsTransparent = isTransparent(otherElement.backgroundColor);
return { return {
start: isMultiPoint start: isMultiPoint
? { mode: undefined } ? { mode: undefined }
@ -320,8 +318,8 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
focusPoint: origin ?? pointFrom<GlobalPoint>(arrow.x, arrow.y), focusPoint: origin ?? pointFrom<GlobalPoint>(arrow.x, arrow.y),
}, },
end: { end: {
mode: "inside", mode: "orbit",
element: otherIsTransparent ? hit : otherElement, element: hit,
focusPoint: point, focusPoint: point,
}, },
}; };

View File

@ -967,6 +967,9 @@ class App extends React.Component<AppProps, AppState> {
} }
} }
private previousHoveredBindableElement: NonDeletedExcalidrawElement | null =
null;
private handleDelayedBindModeChange( private handleDelayedBindModeChange(
arrow: ExcalidrawArrowElement, arrow: ExcalidrawArrowElement,
hoveredElement: NonDeletedExcalidrawElement | null, hoveredElement: NonDeletedExcalidrawElement | null,
@ -1069,7 +1072,11 @@ class App extends React.Component<AppProps, AppState> {
} }
}; };
if (!hoveredElement) { if (
!hoveredElement ||
(this.previousHoveredBindableElement &&
hoveredElement.id !== this.previousHoveredBindableElement.id)
) {
// Clear the timeout if we're not hovering a bindable // Clear the timeout if we're not hovering a bindable
if (this.bindModeHandler) { if (this.bindModeHandler) {
clearTimeout(this.bindModeHandler); clearTimeout(this.bindModeHandler);
@ -1084,6 +1091,8 @@ class App extends React.Component<AppProps, AppState> {
}); });
}); });
} }
this.previousHoveredBindableElement = null;
} else if ( } else if (
!this.bindModeHandler && !this.bindModeHandler &&
(!this.state.newElement || !arrow.startBinding) (!this.state.newElement || !arrow.startBinding)
@ -1091,6 +1100,8 @@ class App extends React.Component<AppProps, AppState> {
// We are hovering a bindable element // We are hovering a bindable element
this.bindModeHandler = setTimeout(effector, BIND_MODE_TIMEOUT); this.bindModeHandler = setTimeout(effector, BIND_MODE_TIMEOUT);
} }
this.previousHoveredBindableElement = hoveredElement;
} }
private cacheEmbeddableRef( private cacheEmbeddableRef(