mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix drag multiple elements bug (#2023)
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
4718c31da5
commit
e7d186b439
9 changed files with 5304 additions and 210 deletions
|
@ -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,
|
||||
|
|
|
@ -14,5 +14,6 @@ export {
|
|||
getElementAtPosition,
|
||||
getElementContainingPosition,
|
||||
hasText,
|
||||
getElementsAtPosition,
|
||||
} from "./comparisons";
|
||||
export { getZoomOrigin, getNormalizedZoom } from "./zoom";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue