| 
					
				 | 
			
			
				@@ -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]); 
			 |