fix for duplicating elements (#261)

This commit is contained in:
David Luzar 2020-01-08 19:54:42 +01:00 committed by GitHub
parent 7f7f51f70b
commit 2122a9cf9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View File

@ -1,4 +1,4 @@
export { newElement } from "./newElement";
export { newElement, duplicateElement } from "./newElement";
export {
getElementAbsoluteCoords,
getDiamondPoints,

View File

@ -32,3 +32,10 @@ export function newElement(
};
return element;
}
export function duplicateElement(element: ReturnType<typeof newElement>) {
const copy = { ...element };
copy.id = nanoid();
copy.seed = randomSeed();
return copy;
}

View File

@ -4,7 +4,13 @@ import rough from "roughjs/bin/wrappers/rough";
import { moveOneLeft, moveAllLeft, moveOneRight, moveAllRight } from "./zindex";
import { randomSeed } from "./random";
import { newElement, resizeTest, isTextElement, textWysiwyg } from "./element";
import {
newElement,
duplicateElement,
resizeTest,
isTextElement,
textWysiwyg
} from "./element";
import {
clearSelection,
getSelectedIndices,
@ -44,7 +50,6 @@ import { PanelCanvas } from "./components/panels/PanelCanvas";
const { elements } = createScene();
const { history } = createHistory();
const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
const CANVAS_WINDOW_OFFSET_LEFT = 250;
@ -683,7 +688,7 @@ class App extends React.Component<{}, AppState> {
elements.push(
...elements.reduce((duplicates, element) => {
if (element.isSelected) {
duplicates.push({ ...element });
duplicates.push(duplicateElement(element));
element.isSelected = false;
}
return duplicates;
@ -1030,10 +1035,10 @@ class App extends React.Component<{}, AppState> {
const dy = y - minY;
parsedElements.forEach(parsedElement => {
parsedElement.x += dx;
parsedElement.y += dy;
parsedElement.seed = randomSeed();
elements.push(parsedElement);
const duplicate = duplicateElement(parsedElement);
duplicate.x += dx;
duplicate.y += dy;
elements.push(duplicate);
});
this.forceUpdate();
}