mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: elements offset incorrectly when action-duplicated during drag (#9275)
All checks were successful
Tests / test (push) Successful in 4m47s
All checks were successful
Tests / test (push) Successful in 4m47s
* fix: elements offset incorrectly when action-duplicated during drag * prevent duplicate action during drag altogether
This commit is contained in:
parent
30983d801a
commit
99d8bff175
2 changed files with 18 additions and 7 deletions
|
@ -52,6 +52,10 @@ export const actionDuplicateSelection = register({
|
||||||
icon: DuplicateIcon,
|
icon: DuplicateIcon,
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState, formData, app) => {
|
perform: (elements, appState, formData, app) => {
|
||||||
|
if (appState.selectedElementsAreBeingDragged) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// duplicate selected point(s) if editing a line
|
// duplicate selected point(s) if editing a line
|
||||||
if (appState.editingLinearElement) {
|
if (appState.editingLinearElement) {
|
||||||
// TODO: Invariants should be checked here instead of duplicateSelectedPoints()
|
// TODO: Invariants should be checked here instead of duplicateSelectedPoints()
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
} from "./typeChecks";
|
} from "./typeChecks";
|
||||||
|
|
||||||
import type { Bounds } from "./bounds";
|
import type { Bounds } from "./bounds";
|
||||||
import type { NonDeletedExcalidrawElement } from "./types";
|
import type { ExcalidrawElement, NonDeletedExcalidrawElement } from "./types";
|
||||||
import type Scene from "../scene/Scene";
|
import type Scene from "../scene/Scene";
|
||||||
import type {
|
import type {
|
||||||
AppState,
|
AppState,
|
||||||
|
@ -78,13 +78,20 @@ export const dragSelectedElements = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const commonBounds = getCommonBounds(
|
const origElements: ExcalidrawElement[] = [];
|
||||||
Array.from(elementsToUpdate).map(
|
|
||||||
(el) => pointerDownState.originalElements.get(el.id) ?? el,
|
for (const element of elementsToUpdate) {
|
||||||
),
|
const origElement = pointerDownState.originalElements.get(element.id);
|
||||||
);
|
// if original element is not set (e.g. when you duplicate during a drag
|
||||||
|
// operation), exit to avoid undefined behavior
|
||||||
|
if (!origElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
origElements.push(origElement);
|
||||||
|
}
|
||||||
|
|
||||||
const adjustedOffset = calculateOffset(
|
const adjustedOffset = calculateOffset(
|
||||||
commonBounds,
|
getCommonBounds(origElements),
|
||||||
offset,
|
offset,
|
||||||
snapOffset,
|
snapOffset,
|
||||||
gridSize,
|
gridSize,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue