XPositionReference: Fix Selector and Append
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Siklos 2022-08-15 22:26:59 +02:00
parent 522cd722c0
commit 4fbc67835c
3 changed files with 31 additions and 6 deletions

View file

@ -7,6 +7,7 @@ import { getCurrentHistory } from './Editor';
import IProperties from '../../Interfaces/IProperties';
import { AddMethod } from '../../Enums/AddMethod';
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
import { transformPosition } from '../SVG/Elements/Container';
/**
* Select a container
@ -248,13 +249,30 @@ export function AddContainer(
setHistoryCurrentStep(history.length - 1);
}
function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, parentClone: IContainerModel, x: number): number {
/**
* Returns a new offset by applying an Add method (append, insert etc.)
* See AddMethod
* @param index Index of the container
* @param containerConfig Configuration of a container
* @param parent Parent container
* @param x Additionnal offset
* @returns New offset
*/
function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, parent: IContainerModel, x: number): number {
if (index > 0 && (
containerConfig.AddMethod === undefined ||
containerConfig.AddMethod === AddMethod.Append)) {
const lastChild: IContainerModel | undefined = parentClone.children.at(index - 1);
const lastChild: IContainerModel | undefined = parent.children.at(index - 1);
if (lastChild !== undefined) {
x += lastChild.properties.x + Number(lastChild.properties.width);
const [transformedX] = transformPosition(
Number(lastChild.properties.x),
Number(lastChild.properties.y),
Number(lastChild.properties.width),
lastChild.properties.XPositionReference
);
x += transformedX + Number(lastChild.properties.width);
}
}
return x;