From 4bb92e219d4d4ce7765054db9cd62b665e54a3e4 Mon Sep 17 00:00:00 2001 From: Eric NGUYEN Date: Wed, 21 Sep 2022 16:46:42 +0200 Subject: [PATCH] Fix behaviors not apply on sibling when deleting a container + Fix container not able to move because sort is done after --- .../Editor/Actions/ContainerOperations.ts | 11 +++--- src/Components/Editor/Behaviors/Behaviors.ts | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Components/Editor/Actions/ContainerOperations.ts b/src/Components/Editor/Actions/ContainerOperations.ts index 7457a1f..6c254de 100644 --- a/src/Components/Editor/Actions/ContainerOperations.ts +++ b/src/Components/Editor/Actions/ContainerOperations.ts @@ -2,7 +2,7 @@ import { IHistoryState } from '../../../Interfaces/IHistoryState'; import { ContainerModel, IContainerModel } from '../../../Interfaces/IContainerModel'; import { FindContainerById, MakeIterator } from '../../../utils/itertools'; import { GetCurrentHistory } from '../Editor'; -import { ApplyBehaviors, ApplyBehaviorsOnSiblingsChildren } from '../Behaviors/Behaviors'; +import { ApplyBehaviors, ApplyBehaviorsOnSiblings, ApplyBehaviorsOnSiblingsChildren } from '../Behaviors/Behaviors'; import { ISymbolModel } from '../../../Interfaces/ISymbolModel'; import Swal from 'sweetalert2'; import { PropertyType } from '../../../Enums/PropertyType'; @@ -79,7 +79,7 @@ export function DeleteContainer( throw new Error('[DeleteContainer] Could not find container among parent\'s children'); } - ApplyBehaviorsOnSiblingsChildren(container, current.symbols); + ApplyBehaviorsOnSiblings(container, current.symbols); // Select the previous container // or select the one above @@ -240,14 +240,15 @@ function SetContainer( container.properties.linkedSymbolId, symbols ); + + // sort the children list by their position + SortChildren(container.parent); + // Apply special behaviors: rigid, flex, symbol, anchor ApplyBehaviors(container, symbols); // Apply special behaviors on siblings ApplyBehaviorsOnSiblingsChildren(container, symbols); - - // sort the children list by their position - SortChildren(container.parent); } /** diff --git a/src/Components/Editor/Behaviors/Behaviors.ts b/src/Components/Editor/Behaviors/Behaviors.ts index 1edfa73..ef894a7 100644 --- a/src/Components/Editor/Behaviors/Behaviors.ts +++ b/src/Components/Editor/Behaviors/Behaviors.ts @@ -84,3 +84,38 @@ export function ApplyBehaviorsOnSiblingsChildren(newContainer: IContainerModel, } }); } + + +/** + * Iterate over the siblings of newContainer and apply the behaviors + * @param newContainer + * @param symbols + * @returns + */ +export function ApplyBehaviorsOnSiblings(newContainer: IContainerModel, symbols: Map): void { + if (newContainer.parent === null || newContainer.parent === undefined) { + return; + } + + newContainer.parent.children + .forEach((container: IContainerModel) => { + ApplyBehaviors(container, symbols); + + if (container.parent != null) { + const overlappingContainers = GetOverlappingContainers(container, container.parent.children); + if (overlappingContainers.length > 0) { + container.properties.warning = `There are overlapping containers: ${overlappingContainers.map(c => c.properties.id).join(' ')}`; + } else { + container.properties.warning = ''; + } + } + if (container === newContainer) { + return; + } + + for (const child of container.children) { + ApplyBehaviors(child, symbols); + } + }); +} +