mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fix group element removing (#1676)
This commit is contained in:
parent
17e9cc4506
commit
f413bab3de
11 changed files with 478 additions and 43 deletions
|
@ -7,15 +7,31 @@ export function selectGroup(
|
|||
appState: AppState,
|
||||
elements: readonly NonDeleted<ExcalidrawElement>[],
|
||||
): AppState {
|
||||
const elementsInGroup = elements.filter((element) =>
|
||||
element.groupIds.includes(groupId),
|
||||
);
|
||||
|
||||
if (elementsInGroup.length < 2) {
|
||||
if (
|
||||
appState.selectedGroupIds[groupId] ||
|
||||
appState.editingGroupId === groupId
|
||||
) {
|
||||
return {
|
||||
...appState,
|
||||
selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: false },
|
||||
editingGroupId: null,
|
||||
};
|
||||
}
|
||||
return appState;
|
||||
}
|
||||
|
||||
return {
|
||||
...appState,
|
||||
selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: true },
|
||||
selectedElementIds: {
|
||||
...appState.selectedElementIds,
|
||||
...Object.fromEntries(
|
||||
elements
|
||||
.filter((element) => element.groupIds.includes(groupId))
|
||||
.map((element) => [element.id, true]),
|
||||
elementsInGroup.map((element) => [element.id, true]),
|
||||
),
|
||||
},
|
||||
};
|
||||
|
@ -89,8 +105,8 @@ export function getSelectedGroupIdForElement(
|
|||
}
|
||||
|
||||
export function getNewGroupIdsForDuplication(
|
||||
groupIds: GroupId[],
|
||||
editingGroupId: GroupId | null,
|
||||
groupIds: ExcalidrawElement["groupIds"],
|
||||
editingGroupId: AppState["editingGroupId"],
|
||||
mapper: (groupId: GroupId) => GroupId,
|
||||
) {
|
||||
const copy = [...groupIds];
|
||||
|
@ -107,9 +123,9 @@ export function getNewGroupIdsForDuplication(
|
|||
}
|
||||
|
||||
export function addToGroup(
|
||||
prevGroupIds: GroupId[],
|
||||
prevGroupIds: ExcalidrawElement["groupIds"],
|
||||
newGroupId: GroupId,
|
||||
editingGroupId: GroupId | null,
|
||||
editingGroupId: AppState["editingGroupId"],
|
||||
) {
|
||||
// insert before the editingGroupId, or push to the end.
|
||||
const groupIds = [...prevGroupIds];
|
||||
|
@ -123,7 +139,7 @@ export function addToGroup(
|
|||
}
|
||||
|
||||
export function removeFromSelectedGroups(
|
||||
groupIds: GroupId[],
|
||||
groupIds: ExcalidrawElement["groupIds"],
|
||||
selectedGroupIds: { [groupId: string]: boolean },
|
||||
) {
|
||||
return groupIds.filter((groupId) => !selectedGroupIds[groupId]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue