CMD + D to Duplicate Selection (#982)
* cmd+d to duplicate selection * use duplicateElement instead * use duplicateElement instead * Update actionDuplicateSelection.ts * select the new duplicated element * add locale * use event.key instead of event.code Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
6966a7a008
commit
ae9b64a623
29
src/actions/actionDuplicateSelection.ts
Normal file
29
src/actions/actionDuplicateSelection.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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]) {
|
||||||
|
const newElement = duplicateElement(element);
|
||||||
|
newElement.x = newElement.x + 10;
|
||||||
|
newElement.y = newElement.y + 10;
|
||||||
|
appState.selectedElementIds[newElement.id] = true;
|
||||||
|
delete appState.selectedElementIds[element.id];
|
||||||
|
return acc.concat([element, newElement]);
|
||||||
|
}
|
||||||
|
return acc.concat(element);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
contextItemLabel: "labels.duplicateSelection",
|
||||||
|
keyTest: event => event[KEYS.CTRL_OR_CMD] && event.key === "d",
|
||||||
|
});
|
@ -6,6 +6,7 @@ export {
|
|||||||
actionSendToBack,
|
actionSendToBack,
|
||||||
} from "./actionZindex";
|
} from "./actionZindex";
|
||||||
export { actionSelectAll } from "./actionSelectAll";
|
export { actionSelectAll } from "./actionSelectAll";
|
||||||
|
export { actionDuplicateSelection } from "./actionDuplicateSelection";
|
||||||
export {
|
export {
|
||||||
actionChangeStrokeColor,
|
actionChangeStrokeColor,
|
||||||
actionChangeBackgroundColor,
|
actionChangeBackgroundColor,
|
||||||
|
@ -43,7 +43,8 @@
|
|||||||
"drawingCanvas": "Drawing Canvas",
|
"drawingCanvas": "Drawing Canvas",
|
||||||
"layers": "Layers",
|
"layers": "Layers",
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
"createRoom": "Share a live-collaboration session"
|
"createRoom": "Share a live-collaboration session",
|
||||||
|
"duplicateSelection": "Duplicate selected elements"
|
||||||
},
|
},
|
||||||
"buttons": {
|
"buttons": {
|
||||||
"clearReset": "Reset the canvas",
|
"clearReset": "Reset the canvas",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user