Fix drag multiple elements bug (#2023)

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
João Forja 2020-08-26 17:37:44 +01:00 committed by GitHub
parent 4718c31da5
commit e7d186b439
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 5304 additions and 210 deletions

View file

@ -34,6 +34,8 @@ export const getElementAtPosition = (
) => {
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
// because array is ordered from lower z-index to highest and we want element z-index
// with higher z-index
for (let i = elements.length - 1; i >= 0; --i) {
const element = elements[i];
if (element.isDeleted) {
@ -48,6 +50,17 @@ export const getElementAtPosition = (
return hitElement;
};
export const getElementsAtPosition = (
elements: readonly NonDeletedExcalidrawElement[],
isAtPositionFn: (element: NonDeletedExcalidrawElement) => boolean,
) => {
// The parameter elements comes ordered from lower z-index to higher.
// We want to preserve that order on the returned array.
return elements.filter(
(element) => !element.isDeleted && isAtPositionFn(element),
);
};
export const getElementContainingPosition = (
elements: readonly ExcalidrawElement[],
x: number,

View file

@ -14,5 +14,6 @@ export {
getElementAtPosition,
getElementContainingPosition,
hasText,
getElementsAtPosition,
} from "./comparisons";
export { getZoomOrigin, getNormalizedZoom } from "./zoom";