7c9e6dd3f1
* support undo/redo for azerty keyboards * migrate to event.key * remove unnecessary shiftKey check Co-authored-by: David Luzar <luzar.david@gmail.com>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { Action } from "./types";
|
|
import { isTextElement, redrawTextBoundingBox } from "../element";
|
|
import { KEYS } from "../keys";
|
|
|
|
let copiedStyles: string = "{}";
|
|
|
|
export const actionCopyStyles: Action = {
|
|
name: "copyStyles",
|
|
perform: elements => {
|
|
const element = elements.find(el => el.isSelected);
|
|
if (element) {
|
|
copiedStyles = JSON.stringify(element);
|
|
}
|
|
return {};
|
|
},
|
|
contextItemLabel: "labels.copyStyles",
|
|
keyTest: event => event[KEYS.META] && event.shiftKey && event.key === "C",
|
|
contextMenuOrder: 0,
|
|
};
|
|
|
|
export const actionPasteStyles: Action = {
|
|
name: "pasteStyles",
|
|
perform: elements => {
|
|
const pastedElement = JSON.parse(copiedStyles);
|
|
return {
|
|
elements: elements.map(element => {
|
|
if (element.isSelected) {
|
|
const newElement = {
|
|
...element,
|
|
shape: null,
|
|
backgroundColor: pastedElement?.backgroundColor,
|
|
strokeWidth: pastedElement?.strokeWidth,
|
|
strokeColor: pastedElement?.strokeColor,
|
|
fillStyle: pastedElement?.fillStyle,
|
|
opacity: pastedElement?.opacity,
|
|
roughness: pastedElement?.roughness,
|
|
};
|
|
if (isTextElement(newElement)) {
|
|
newElement.font = pastedElement?.font;
|
|
redrawTextBoundingBox(newElement);
|
|
}
|
|
return newElement;
|
|
}
|
|
return element;
|
|
}),
|
|
};
|
|
},
|
|
contextItemLabel: "labels.pasteStyles",
|
|
keyTest: event => event[KEYS.META] && event.shiftKey && event.key === "V",
|
|
contextMenuOrder: 1,
|
|
};
|