From 5245276409b8d163c656c9d3a5e9028b8322a59b Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:43:04 +0100 Subject: [PATCH] feat: erase groups atomically (#7545) --- packages/excalidraw/components/App.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 295c9dc08..acbe56741 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -5129,6 +5129,9 @@ class App extends React.Component { let didChange = false; + const processedGroups = new Set(); + const nonDeletedElements = this.scene.getNonDeletedElements(); + const processElements = (elements: ExcalidrawElement[]) => { for (const element of elements) { if (element.locked) { @@ -5143,6 +5146,25 @@ class App extends React.Component { didChange = true; this.elementsPendingErasure.add(element.id); } + + // (un)erase groups atomically + if (didChange && element.groupIds?.length) { + const shallowestGroupId = element.groupIds.at(-1)!; + if (!processedGroups.has(shallowestGroupId)) { + processedGroups.add(shallowestGroupId); + const elems = getElementsInGroup( + nonDeletedElements, + shallowestGroupId, + ); + for (const elem of elems) { + if (event.altKey) { + this.elementsPendingErasure.delete(elem.id); + } else { + this.elementsPendingErasure.add(elem.id); + } + } + } + } } };