Fix group element removing (#1676)

This commit is contained in:
David Luzar 2020-05-30 22:48:57 +02:00 committed by GitHub
parent 17e9cc4506
commit f413bab3de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 478 additions and 43 deletions

View file

@ -1,4 +1,4 @@
import { deleteSelectedElements, isSomeElementSelected } from "../scene";
import { isSomeElementSelected } from "../scene";
import { KEYS } from "../keys";
import { ToolButton } from "../components/ToolButton";
import React from "react";
@ -6,14 +6,49 @@ import { trash } from "../components/icons";
import { t } from "../i18n";
import { register } from "./register";
import { getNonDeletedElements } from "../element";
import { ExcalidrawElement } from "../element/types";
import { AppState } from "../types";
import { newElementWith } from "../element/mutateElement";
import { getElementsInGroup } from "../groups";
const deleteSelectedElements = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
return {
elements: elements.map((el) => {
if (appState.selectedElementIds[el.id]) {
return newElementWith(el, { isDeleted: true });
}
return el;
}),
appState: {
...appState,
selectedElementIds: {},
},
};
};
export const actionDeleteSelected = register({
name: "deleteSelectedElements",
perform: (elements, appState) => {
const {
let {
elements: nextElements,
appState: nextAppState,
} = deleteSelectedElements(elements, appState);
if (appState.editingGroupId) {
const siblingElements = getElementsInGroup(
getNonDeletedElements(nextElements),
appState.editingGroupId!,
);
if (siblingElements.length) {
nextAppState = {
...nextAppState,
selectedElementIds: { [siblingElements[0].id]: true },
};
}
}
return {
elements: nextElements,
appState: {