fix for duplicating elements (#261)
This commit is contained in:
parent
7f7f51f70b
commit
2122a9cf9f
@ -1,4 +1,4 @@
|
|||||||
export { newElement } from "./newElement";
|
export { newElement, duplicateElement } from "./newElement";
|
||||||
export {
|
export {
|
||||||
getElementAbsoluteCoords,
|
getElementAbsoluteCoords,
|
||||||
getDiamondPoints,
|
getDiamondPoints,
|
||||||
|
@ -32,3 +32,10 @@ export function newElement(
|
|||||||
};
|
};
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function duplicateElement(element: ReturnType<typeof newElement>) {
|
||||||
|
const copy = { ...element };
|
||||||
|
copy.id = nanoid();
|
||||||
|
copy.seed = randomSeed();
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
@ -4,7 +4,13 @@ import rough from "roughjs/bin/wrappers/rough";
|
|||||||
|
|
||||||
import { moveOneLeft, moveAllLeft, moveOneRight, moveAllRight } from "./zindex";
|
import { moveOneLeft, moveAllLeft, moveOneRight, moveAllRight } from "./zindex";
|
||||||
import { randomSeed } from "./random";
|
import { randomSeed } from "./random";
|
||||||
import { newElement, resizeTest, isTextElement, textWysiwyg } from "./element";
|
import {
|
||||||
|
newElement,
|
||||||
|
duplicateElement,
|
||||||
|
resizeTest,
|
||||||
|
isTextElement,
|
||||||
|
textWysiwyg
|
||||||
|
} from "./element";
|
||||||
import {
|
import {
|
||||||
clearSelection,
|
clearSelection,
|
||||||
getSelectedIndices,
|
getSelectedIndices,
|
||||||
@ -44,7 +50,6 @@ import { PanelCanvas } from "./components/panels/PanelCanvas";
|
|||||||
|
|
||||||
const { elements } = createScene();
|
const { elements } = createScene();
|
||||||
const { history } = createHistory();
|
const { history } = createHistory();
|
||||||
|
|
||||||
const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
|
const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
|
||||||
|
|
||||||
const CANVAS_WINDOW_OFFSET_LEFT = 250;
|
const CANVAS_WINDOW_OFFSET_LEFT = 250;
|
||||||
@ -683,7 +688,7 @@ class App extends React.Component<{}, AppState> {
|
|||||||
elements.push(
|
elements.push(
|
||||||
...elements.reduce((duplicates, element) => {
|
...elements.reduce((duplicates, element) => {
|
||||||
if (element.isSelected) {
|
if (element.isSelected) {
|
||||||
duplicates.push({ ...element });
|
duplicates.push(duplicateElement(element));
|
||||||
element.isSelected = false;
|
element.isSelected = false;
|
||||||
}
|
}
|
||||||
return duplicates;
|
return duplicates;
|
||||||
@ -1030,10 +1035,10 @@ class App extends React.Component<{}, AppState> {
|
|||||||
const dy = y - minY;
|
const dy = y - minY;
|
||||||
|
|
||||||
parsedElements.forEach(parsedElement => {
|
parsedElements.forEach(parsedElement => {
|
||||||
parsedElement.x += dx;
|
const duplicate = duplicateElement(parsedElement);
|
||||||
parsedElement.y += dy;
|
duplicate.x += dx;
|
||||||
parsedElement.seed = randomSeed();
|
duplicate.y += dy;
|
||||||
elements.push(parsedElement);
|
elements.push(duplicate);
|
||||||
});
|
});
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user