Skip to content

Commit

Permalink
fix: perf issue when ungrouping elements within frame (excalidraw#7265)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Di <[email protected]>
  • Loading branch information
dwelle and ryan-di committed Nov 10, 2023
1 parent 900b317 commit 6363492
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/actions/actionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import {
import { getNonDeletedElements } from "../element";
import { randomId } from "../random";
import { ToolButton } from "../components/ToolButton";
import {
ExcalidrawElement,
ExcalidrawFrameElement,
ExcalidrawTextElement,
} from "../element/types";
import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types";
import { AppClassProperties, AppState } from "../types";
import { isBoundToContainer } from "../element/typeChecks";
import {
getElementsInResizingFrame,
getFrameElements,
groupByFrames,
removeElementsFromFrame,
replaceAllElementsInFrame,
Expand Down Expand Up @@ -190,13 +187,6 @@ export const actionUngroup = register({

let nextElements = [...elements];

const selectedElements = app.scene.getSelectedElements(appState);
const frames = selectedElements
.filter((element) => element.frameId)
.map((element) =>
app.scene.getElement(element.frameId!),
) as ExcalidrawFrameElement[];

const boundTextElementIds: ExcalidrawTextElement["id"][] = [];
nextElements = nextElements.map((element) => {
if (isBoundToContainer(element)) {
Expand All @@ -221,7 +211,19 @@ export const actionUngroup = register({
null,
);

frames.forEach((frame) => {
const selectedElements = app.scene.getSelectedElements(appState);

const selectedElementFrameIds = new Set(
selectedElements
.filter((element) => element.frameId)
.map((element) => element.frameId!),
);

const targetFrames = getFrameElements(elements).filter((frame) =>
selectedElementFrameIds.has(frame.id),
);

targetFrames.forEach((frame) => {
if (frame) {
nextElements = replaceAllElementsInFrame(
nextElements,
Expand Down

0 comments on commit 6363492

Please sign in to comment.