mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: binding text to non-bindable containers and not always preferring selection (#4655)
This commit is contained in:
parent
8e26d5b500
commit
6d0716eb6b
13 changed files with 336 additions and 85 deletions
|
@ -1,9 +1,11 @@
|
|||
import {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawTextContainer,
|
||||
NonDeletedExcalidrawElement,
|
||||
} from "../element/types";
|
||||
|
||||
import { getElementAbsoluteCoords } from "../element";
|
||||
import { isTextBindableContainer } from "../element/typeChecks";
|
||||
|
||||
export const hasBackground = (type: string) =>
|
||||
type === "rectangle" ||
|
||||
|
@ -72,11 +74,11 @@ export const getElementsAtPosition = (
|
|||
);
|
||||
};
|
||||
|
||||
export const getElementContainingPosition = (
|
||||
export const getTextBindableContainerAtPosition = (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
x: number,
|
||||
y: number,
|
||||
) => {
|
||||
): ExcalidrawTextContainer | null => {
|
||||
let hitElement = null;
|
||||
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||
for (let index = elements.length - 1; index >= 0; --index) {
|
||||
|
@ -89,5 +91,5 @@ export const getElementContainingPosition = (
|
|||
break;
|
||||
}
|
||||
}
|
||||
return hitElement;
|
||||
return isTextBindableContainer(hitElement) ? hitElement : null;
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ export {
|
|||
canHaveArrowheads,
|
||||
canChangeSharpness,
|
||||
getElementAtPosition,
|
||||
getElementContainingPosition,
|
||||
getTextBindableContainerAtPosition,
|
||||
hasText,
|
||||
getElementsAtPosition,
|
||||
} from "./comparisons";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue