Compare commits
1 Commits
master
...
arrow-fram
Author | SHA1 | Date | |
---|---|---|---|
|
c0efc16270 |
@ -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 = (
|
||||
|
10
src/frame.ts
10
src/frame.ts
@ -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 ------------------------------------
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user