From 1fd347cade5b51866388a67b6f00e586706c2e8b Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 23 Dec 2021 21:36:29 +0530 Subject: [PATCH] fix: don't select binded text when ungrouping (#4470) --- src/actions/actionGroup.tsx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/actions/actionGroup.tsx b/src/actions/actionGroup.tsx index 92de75d7..af680ac9 100644 --- a/src/actions/actionGroup.tsx +++ b/src/actions/actionGroup.tsx @@ -17,8 +17,9 @@ import { import { getNonDeletedElements } from "../element"; import { randomId } from "../random"; import { ToolButton } from "../components/ToolButton"; -import { ExcalidrawElement } from "../element/types"; +import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types"; import { AppState } from "../types"; +import { isBoundToContainer } from "../element/typeChecks"; const allElementsInSameGroup = (elements: readonly ExcalidrawElement[]) => { if (elements.length >= 2) { @@ -151,7 +152,12 @@ export const actionUngroup = register({ if (groupIds.length === 0) { return { appState, elements, commitToHistory: false }; } + + const boundTextElementIds: ExcalidrawTextElement["id"][] = []; const nextElements = elements.map((element) => { + if (isBoundToContainer(element)) { + boundTextElementIds.push(element.id); + } const nextGroupIds = removeFromSelectedGroups( element.groupIds, appState.selectedGroupIds, @@ -163,11 +169,19 @@ export const actionUngroup = register({ groupIds: nextGroupIds, }); }); + + const updateAppState = selectGroupsForSelectedElements( + { ...appState, selectedGroupIds: {} }, + getNonDeletedElements(nextElements), + ); + + // remove binded text elements from selection + boundTextElementIds.forEach( + (id) => (updateAppState.selectedElementIds[id] = false), + ); return { - appState: selectGroupsForSelectedElements( - { ...appState, selectedGroupIds: {} }, - getNonDeletedElements(nextElements), - ), + appState: updateAppState, + elements: nextElements, commitToHistory: true, };