Fix behaviors not apply on sibling when deleting a container + Fix container not able to move because sort is done after

This commit is contained in:
Eric NGUYEN 2022-09-21 16:46:42 +02:00
parent d875e33f93
commit 4bb92e219d
2 changed files with 41 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import { IHistoryState } from '../../../Interfaces/IHistoryState';
import { ContainerModel, IContainerModel } from '../../../Interfaces/IContainerModel'; import { ContainerModel, IContainerModel } from '../../../Interfaces/IContainerModel';
import { FindContainerById, MakeIterator } from '../../../utils/itertools'; import { FindContainerById, MakeIterator } from '../../../utils/itertools';
import { GetCurrentHistory } from '../Editor'; import { GetCurrentHistory } from '../Editor';
import { ApplyBehaviors, ApplyBehaviorsOnSiblingsChildren } from '../Behaviors/Behaviors'; import { ApplyBehaviors, ApplyBehaviorsOnSiblings, ApplyBehaviorsOnSiblingsChildren } from '../Behaviors/Behaviors';
import { ISymbolModel } from '../../../Interfaces/ISymbolModel'; import { ISymbolModel } from '../../../Interfaces/ISymbolModel';
import Swal from 'sweetalert2'; import Swal from 'sweetalert2';
import { PropertyType } from '../../../Enums/PropertyType'; import { PropertyType } from '../../../Enums/PropertyType';
@ -79,7 +79,7 @@ export function DeleteContainer(
throw new Error('[DeleteContainer] Could not find container among parent\'s children'); throw new Error('[DeleteContainer] Could not find container among parent\'s children');
} }
ApplyBehaviorsOnSiblingsChildren(container, current.symbols); ApplyBehaviorsOnSiblings(container, current.symbols);
// Select the previous container // Select the previous container
// or select the one above // or select the one above
@ -240,14 +240,15 @@ function SetContainer(
container.properties.linkedSymbolId, container.properties.linkedSymbolId,
symbols symbols
); );
// sort the children list by their position
SortChildren(container.parent);
// Apply special behaviors: rigid, flex, symbol, anchor // Apply special behaviors: rigid, flex, symbol, anchor
ApplyBehaviors(container, symbols); ApplyBehaviors(container, symbols);
// Apply special behaviors on siblings // Apply special behaviors on siblings
ApplyBehaviorsOnSiblingsChildren(container, symbols); ApplyBehaviorsOnSiblingsChildren(container, symbols);
// sort the children list by their position
SortChildren(container.parent);
} }
/** /**

View file

@ -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<string, ISymbolModel>): 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);
}
});
}