diff --git a/src/actions/actionDuplicateSelection.tsx b/src/actions/actionDuplicateSelection.tsx index 60ebb54e0..dda172f33 100644 --- a/src/actions/actionDuplicateSelection.tsx +++ b/src/actions/actionDuplicateSelection.tsx @@ -259,23 +259,26 @@ const duplicateElements = ( return { elements: finalElements, - appState: selectGroupsForSelectedElements( - { - ...appState, - selectedGroupIds: {}, - selectedElementIds: nextElementsToSelect.reduce( - (acc: Record, element) => { - if (!isBoundToContainer(element)) { - acc[element.id] = true; - } - return acc; - }, - {}, - ), - }, - getNonDeletedElements(finalElements), - appState, - null, - ) as AppState, + appState: { + ...appState, + ...selectGroupsForSelectedElements( + { + ...appState, + selectedGroupIds: {}, + selectedElementIds: nextElementsToSelect.reduce( + (acc: Record, element) => { + if (!isBoundToContainer(element)) { + acc[element.id] = true; + } + return acc; + }, + {}, + ), + }, + getNonDeletedElements(finalElements), + appState, + null, + ), + }, }; }; diff --git a/src/actions/actionSelectAll.ts b/src/actions/actionSelectAll.ts index 33e506fda..6b30991f7 100644 --- a/src/actions/actionSelectAll.ts +++ b/src/actions/actionSelectAll.ts @@ -6,7 +6,6 @@ import { ExcalidrawElement } from "../element/types"; import { isLinearElement } from "../element/typeChecks"; import { LinearElementEditor } from "../element/linearElementEditor"; import { excludeElementsInFramesFromSelection } from "../scene/selection"; -import { AppState } from "../types"; export const actionSelectAll = register({ name: "selectAll", @@ -29,22 +28,25 @@ export const actionSelectAll = register({ }, {}); return { - appState: selectGroupsForSelectedElements( - { - ...appState, - selectedLinearElement: - // single linear element selected - Object.keys(selectedElementIds).length === 1 && - isLinearElement(elements[0]) - ? new LinearElementEditor(elements[0], app.scene) - : null, - editingGroupId: null, - selectedElementIds, - }, - getNonDeletedElements(elements), - appState, - app, - ) as AppState, + appState: { + ...appState, + ...selectGroupsForSelectedElements( + { + ...appState, + selectedLinearElement: + // single linear element selected + Object.keys(selectedElementIds).length === 1 && + isLinearElement(elements[0]) + ? new LinearElementEditor(elements[0], app.scene) + : null, + editingGroupId: null, + selectedElementIds, + }, + getNonDeletedElements(elements), + appState, + app, + ), + }, commitToHistory: true, }; }, diff --git a/src/components/App.tsx b/src/components/App.tsx index f6bbac14d..4f767296b 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -7591,21 +7591,24 @@ class App extends React.Component { this.setState( { ...(element && !this.state.selectedElementIds[element.id] - ? selectGroupsForSelectedElements( - { - ...this.state, - selectedElementIds: { [element.id]: true }, - selectedLinearElement: isLinearElement(element) - ? new LinearElementEditor(element, this.scene) - : null, - }, - this.scene.getNonDeletedElements(), - this.state, - this, - ) + ? { + ...this.state, + ...selectGroupsForSelectedElements( + { + ...this.state, + selectedElementIds: { [element.id]: true }, + selectedLinearElement: isLinearElement(element) + ? new LinearElementEditor(element, this.scene) + : null, + }, + this.scene.getNonDeletedElements(), + this.state, + this, + ), + } : this.state), showHyperlinkPopup: false, - } as AppState, + }, () => { this.setState({ contextMenu: { top, left, items: this.getContextMenuItems(type) }, diff --git a/src/groups.ts b/src/groups.ts index e54ad371c..269566173 100644 --- a/src/groups.ts +++ b/src/groups.ts @@ -21,12 +21,15 @@ export const selectGroup = ( InteractiveCanvasAppState, "selectedGroupIds" | "selectedElementIds" | "editingGroupId" > => { - const elementsInGroup = elements.reduce((acc, element) => { - if (element.groupIds.includes(groupId)) { - acc[element.id] = true; - } - return acc; - }, {} as Record); + const elementsInGroup = elements.reduce( + (acc: Record, element) => { + if (element.groupIds.includes(groupId)) { + acc[element.id] = true; + } + return acc; + }, + {}, + ); if (Object.keys(elementsInGroup).length < 2) { if ( @@ -48,7 +51,7 @@ export const selectGroup = ( selectedElementIds: { ...appState.selectedElementIds, ...elementsInGroup, - } as AppState["selectedElementIds"], + }, }; }; @@ -92,21 +95,24 @@ export const selectGroups = (function () { // Gather all the elements within selected groups const groupElementsIndex: Record = {}; - const selectedElementIdsInGroups = elements.reduce((acc, element) => { - const groupId = element.groupIds.find((id) => selectedGroupIds[id]); + const selectedElementIdsInGroups = elements.reduce( + (acc: Record, element) => { + const groupId = element.groupIds.find((id) => selectedGroupIds[id]); - if (groupId) { - acc[element.id] = true; + if (groupId) { + acc[element.id] = true; - // Populate the index - if (!Array.isArray(groupElementsIndex[groupId])) { - groupElementsIndex[groupId] = [element.id]; - } else { - groupElementsIndex[groupId].push(element.id); + // Populate the index + if (!Array.isArray(groupElementsIndex[groupId])) { + groupElementsIndex[groupId] = [element.id]; + } else { + groupElementsIndex[groupId].push(element.id); + } } - } - return acc; - }, {} as Record); + return acc; + }, + {}, + ); for (const groupId of Object.keys(groupElementsIndex)) { // If there is one element in the group, and the group is selected or it's being edited, it's not a group @@ -126,7 +132,7 @@ export const selectGroups = (function () { selectedElementIds: { ...appState.selectedElementIds, ...selectedElementIdsInGroups, - } as AppState["selectedElementIds"], + }, }; return lastAppState;