fix: do not bind invisible part of an element to arrow

This commit is contained in:
Ryan Di 2023-07-19 18:15:04 +08:00
parent 9f76f8677b
commit c0efc16270
2 changed files with 39 additions and 4 deletions

View File

@ -27,6 +27,7 @@ import { LinearElementEditor } from "./linearElementEditor";
import { arrayToMap, tupleToCoors } from "../utils";
import { KEYS } from "../keys";
import { getBoundTextElement, handleBindTextResize } from "./textElement";
import { getContainingFrame, isPointInFrame } from "../frame";
export type SuggestedBinding =
| NonDeleted<ExcalidrawBindableElement>
@ -274,6 +275,18 @@ export const getHoveredElementForBinding = (
isBindableElement(element, false) &&
bindingBorderTest(element, pointerCoords),
);
if (hoveredElement) {
const frame = getContainingFrame(hoveredElement);
if (frame) {
if (isPointInFrame(pointerCoords, frame)) {
return hoveredElement as NonDeleted<ExcalidrawBindableElement>;
}
return null;
}
}
return hoveredElement as NonDeleted<ExcalidrawBindableElement> | null;
};
@ -499,10 +512,22 @@ const getElligibleElementsForBindingElement = (
return [
getElligibleElementForBindingElement(linearElement, "start"),
getElligibleElementForBindingElement(linearElement, "end"),
].filter(
(element): element is NonDeleted<ExcalidrawBindableElement> =>
element != null,
);
].filter((element): element is NonDeleted<ExcalidrawBindableElement> => {
if (element != null) {
const frame = getContainingFrame(element);
return frame
? isPointInFrame(
getLinearElementEdgeCoors(linearElement, "start"),
frame,
) ||
isPointInFrame(
getLinearElementEdgeCoors(linearElement, "end"),
frame,
)
: true;
}
return false;
});
};
const getElligibleElementForBindingElement = (

View File

@ -1,6 +1,7 @@
import {
getCommonBounds,
getElementAbsoluteCoords,
getElementBounds,
isTextElement,
} from "./element";
import {
@ -299,6 +300,15 @@ export const groupsAreCompletelyOutOfFrame = (
);
};
export const isPointInFrame = (
{ x, y }: { x: number; y: number },
frame: ExcalidrawFrameElement,
) => {
const [x1, y1, x2, y2] = getElementBounds(frame);
return x >= x1 && x <= x2 && y >= y1 && y <= y2;
};
// --------------------------- Frame Utils ------------------------------------
/**