Browse Source

fix: lock/unlock elements in frames

Ryan Di 1 year ago
parent
commit
c9af72e2ee
1 changed files with 7 additions and 8 deletions
  1. 7 8
      src/actions/actionElementLock.ts

+ 7 - 8
src/actions/actionElementLock.ts

@@ -10,17 +10,12 @@ const shouldLock = (elements: readonly ExcalidrawElement[]) =>
 export const actionToggleElementLock = register({
   name: "toggleElementLock",
   trackEvent: { category: "element" },
-  predicate: (elements, appState, _, app) => {
-    const selectedElements = app.scene.getSelectedElements(appState);
-    return !selectedElements.some(
-      (element) => element.locked && element.frameId,
-    );
-  },
   perform: (elements, appState, _, app) => {
+    // Frames and their children should not be selected at the same time.
+    // Therefore, there's no need to include elements in frame in the selection.
     const selectedElements = app.scene.getSelectedElements({
       selectedElementIds: appState.selectedElementIds,
       includeBoundTextElement: true,
-      includeElementsInFrames: true,
     });
 
     if (!selectedElements.length) {
@@ -31,7 +26,11 @@ export const actionToggleElementLock = register({
     const selectedElementsMap = arrayToMap(selectedElements);
     return {
       elements: elements.map((element) => {
-        if (!selectedElementsMap.has(element.id)) {
+        if (
+          !selectedElementsMap.has(element.id) &&
+          element.frameId &&
+          !selectedElementsMap.has(element.frameId)
+        ) {
           return element;
         }