provide an optional direction when shape switching

This commit is contained in:
Ryan Di 2025-04-02 17:05:01 +11:00
parent 66812e5ab3
commit 3272841b23
2 changed files with 9 additions and 2 deletions

View file

@ -408,10 +408,12 @@ export const switchShapes = (
generic,
linear,
nextType,
direction = "right",
}: {
generic?: boolean;
linear?: boolean;
nextType?: GenericSwitchableToolType | LinearSwitchableToolType;
direction?: "left" | "right";
} = {},
): boolean => {
if (!generic && !linear) {
@ -428,6 +430,8 @@ export const switchShapes = (
{},
);
const advancement = direction === "right" ? 1 : -1;
if (generic) {
const selectedGenericSwitchableElements =
getGenericSwitchableElements(selectedElements);
@ -445,7 +449,8 @@ export const switchShapes = (
nextType =
nextType ??
(GENERIC_SWITCHABLE_SHAPES[
(index + 1) % GENERIC_SWITCHABLE_SHAPES.length
(index + GENERIC_SWITCHABLE_SHAPES.length + advancement) %
GENERIC_SWITCHABLE_SHAPES.length
] as GenericSwitchableToolType);
selectedGenericSwitchableElements.forEach((element) => {
@ -516,7 +521,8 @@ export const switchShapes = (
nextType =
nextType ??
(LINEAR_SWITCHABLE_SHAPES[
(index + 1) % LINEAR_SWITCHABLE_SHAPES.length
(index + LINEAR_SWITCHABLE_SHAPES.length + advancement) %
LINEAR_SWITCHABLE_SHAPES.length
] as LinearSwitchableToolType);
selectedElements.forEach((element) => {