fix: Alt-duplication doesn't place the duplicate at the last moment where Alt is pressed

fix: Shift + Alt
This commit is contained in:
Mark Tolmacs
2025-10-11 14:16:51 +02:00
parent 19b03b4ca9
commit 20eaddee92
2 changed files with 11 additions and 4 deletions

View File

@@ -95,7 +95,7 @@ export const dragSelectedElements = (
origElements.push(origElement); origElements.push(origElement);
} }
const adjustedOffset = calculateOffset( const adjustedOffset = calculateDragOffset(
getCommonBounds(origElements), getCommonBounds(origElements),
offset, offset,
snapOffset, snapOffset,
@@ -125,7 +125,7 @@ export const dragSelectedElements = (
}); });
}; };
const calculateOffset = ( export const calculateDragOffset = (
commonBounds: Bounds, commonBounds: Bounds,
dragOffset: { x: number; y: number }, dragOffset: { x: number; y: number },
snapOffset: { x: number; y: number }, snapOffset: { x: number; y: number },

View File

@@ -240,6 +240,7 @@ import {
StoreDelta, StoreDelta,
type ApplyToOptions, type ApplyToOptions,
positionElementsOnGrid, positionElementsOnGrid,
calculateDragOffset,
} from "@excalidraw/element"; } from "@excalidraw/element";
import type { LocalPoint, Radians } from "@excalidraw/math"; import type { LocalPoint, Radians } from "@excalidraw/math";
@@ -8782,14 +8783,20 @@ class App extends React.Component<AppProps, AppState> {
); );
}); });
const { x: diffX, y: diffY } = calculateDragOffset(
getCommonBounds(elementsWithDuplicates),
dragOffset,
snapOffset,
event[KEYS.CTRL_OR_CMD] ? null : this.getEffectiveGridSize(),
);
const mappedClonedElements = elementsWithDuplicates.map((el) => { const mappedClonedElements = elementsWithDuplicates.map((el) => {
if (idsOfElementsToDuplicate.has(el.id)) { if (idsOfElementsToDuplicate.has(el.id)) {
const origEl = pointerDownState.originalElements.get(el.id); const origEl = pointerDownState.originalElements.get(el.id);
if (origEl) { if (origEl) {
return newElementWith(el, { return newElementWith(el, {
x: origEl.x, x: origEl.x + diffX,
y: origEl.y, y: origEl.y + diffY,
}); });
} }
} }