diff --git a/src/actions/actionGroup.tsx b/src/actions/actionGroup.tsx index c4b5aeb55..c4a8f603f 100644 --- a/src/actions/actionGroup.tsx +++ b/src/actions/actionGroup.tsx @@ -149,11 +149,14 @@ export const actionGroup = register({ ]; return { - appState: selectGroup( - newGroupId, - { ...appState, selectedGroupIds: {} }, - getNonDeletedElements(nextElements), - ) as AppState, + appState: { + ...appState, + ...selectGroup( + newGroupId, + { ...appState, selectedGroupIds: {} }, + getNonDeletedElements(nextElements), + ), + }, elements: nextElements, commitToHistory: true, }; @@ -216,7 +219,7 @@ export const actionUngroup = register({ getNonDeletedElements(nextElements), appState, null, - ) as AppState; + ); frames.forEach((frame) => { if (frame) { @@ -243,7 +246,7 @@ export const actionUngroup = register({ ); return { - appState: updateAppState, + appState: { ...appState, ...updateAppState }, elements: nextElements, commitToHistory: true, }; diff --git a/src/groups.ts b/src/groups.ts index 8d6102b3c..e54ad371c 100644 --- a/src/groups.ts +++ b/src/groups.ts @@ -17,7 +17,10 @@ export const selectGroup = ( groupId: GroupId, appState: InteractiveCanvasAppState, elements: readonly NonDeleted[], -): InteractiveCanvasAppState => { +): Pick< + InteractiveCanvasAppState, + "selectedGroupIds" | "selectedElementIds" | "editingGroupId" +> => { const elementsInGroup = elements.reduce((acc, element) => { if (element.groupIds.includes(groupId)) { acc[element.id] = true; @@ -31,7 +34,7 @@ export const selectGroup = ( appState.editingGroupId === groupId ) { return { - ...appState, + selectedElementIds: appState.selectedElementIds, selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: false }, editingGroupId: null, }; @@ -40,7 +43,7 @@ export const selectGroup = ( } return { - ...appState, + editingGroupId: appState.editingGroupId, selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: true }, selectedElementIds: { ...appState.selectedElementIds, @@ -226,12 +229,13 @@ export const selectGroupsFromGivenElements = ( } if (groupIds.length > 0) { const groupId = groupIds[groupIds.length - 1]; - nextAppState = selectGroup(groupId, nextAppState, elements); + nextAppState = { + ...nextAppState, + ...selectGroup(groupId, nextAppState, elements), + }; } } - // nextAppState = selectGroups(elements, elements, appState); - return nextAppState.selectedGroupIds; };