From 4944a739c8d80adfdf4b502758d7a0a7ebaeeca2 Mon Sep 17 00:00:00 2001 From: feng Date: Mon, 21 Apr 2025 14:38:40 +0900 Subject: [PATCH] fix: hide the alignment buttons if there is only one group selected (they do nothing if only one group is selected) --- packages/excalidraw/actions/actionAlign.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/excalidraw/actions/actionAlign.tsx b/packages/excalidraw/actions/actionAlign.tsx index 46023d61e..ffea3e948 100644 --- a/packages/excalidraw/actions/actionAlign.tsx +++ b/packages/excalidraw/actions/actionAlign.tsx @@ -8,6 +8,8 @@ import { KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common"; import { alignElements } from "@excalidraw/element/align"; +import { getMaximumGroups } from "@excalidraw/element/groups"; + import type { ExcalidrawElement } from "@excalidraw/element/types"; import type { Alignment } from "@excalidraw/element/align"; @@ -36,8 +38,12 @@ export const alignActionsPredicate = ( app: AppClassProperties, ) => { const selectedElements = app.scene.getSelectedElements(appState); + const groups = getMaximumGroups( + selectedElements, + app.scene.getNonDeletedElementsMap(), + ); return ( - selectedElements.length > 1 && + groups.length > 1 && // TODO enable aligning frames when implemented properly !selectedElements.some((el) => isFrameLikeElement(el)) );