fix: lock/unlock elements in frames

This commit is contained in:
Ryan Di 2023-11-08 15:48:36 +08:00
parent 18a7b97515
commit c9af72e2ee

View File

@ -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;
}