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

@ -4112,6 +4112,7 @@ class App extends React.Component<AppProps, AppState> {
switchShapes(this, { switchShapes(this, {
generic, generic,
linear, linear,
direction: event.shiftKey ? "left" : "right",
}) })
) { ) {
this.store.shouldCaptureIncrement(); this.store.shouldCaptureIncrement();

View file

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