2020-03-16 22:53:02 +01:00
|
|
|
import { KEYS } from "../keys";
|
|
|
|
import { register } from "./register";
|
|
|
|
import { ExcalidrawElement } from "../element/types";
|
|
|
|
import { duplicateElement } from "../element";
|
|
|
|
|
|
|
|
export const actionDuplicateSelection = register({
|
|
|
|
name: "duplicateSelection",
|
|
|
|
perform: (elements, appState) => {
|
|
|
|
return {
|
|
|
|
appState,
|
|
|
|
elements: elements.reduce(
|
|
|
|
(acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
|
|
|
|
if (appState.selectedElementIds[element.id]) {
|
2020-03-17 20:55:40 +01:00
|
|
|
const newElement = duplicateElement(element, {
|
|
|
|
x: element.x + 10,
|
|
|
|
y: element.y + 10,
|
|
|
|
});
|
2020-03-16 22:53:02 +01:00
|
|
|
appState.selectedElementIds[newElement.id] = true;
|
|
|
|
delete appState.selectedElementIds[element.id];
|
|
|
|
return acc.concat([element, newElement]);
|
|
|
|
}
|
|
|
|
return acc.concat(element);
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
),
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-03-16 22:53:02 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
contextItemLabel: "labels.duplicateSelection",
|
2020-03-23 13:05:07 +02:00
|
|
|
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === "d",
|
2020-03-16 22:53:02 +01:00
|
|
|
});
|