mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
save copied styles in memory
This commit is contained in:
parent
00af6dc635
commit
510f4101bb
1 changed files with 17 additions and 33 deletions
|
@ -55,6 +55,8 @@ const KEYS = {
|
|||
BACKSPACE: "Backspace"
|
||||
};
|
||||
|
||||
let COPIED_STYLES: string = "{}";
|
||||
|
||||
function isArrowKey(keyCode: string) {
|
||||
return (
|
||||
keyCode === KEYS.ARROW_LEFT ||
|
||||
|
@ -215,43 +217,25 @@ class App extends React.Component<{}, AppState> {
|
|||
} else if (event.metaKey && event.shiftKey && event.code === "KeyC") {
|
||||
const element = elements.find(el => el.isSelected);
|
||||
if (element) {
|
||||
if (!navigator.clipboard) return;
|
||||
navigator.clipboard
|
||||
.writeText(JSON.stringify(element))
|
||||
.catch(err => alert("Failed to copy shape style!"));
|
||||
COPIED_STYLES = JSON.stringify(element);
|
||||
}
|
||||
// Paste Styles: Cmd-Shift-V
|
||||
} else if (event.metaKey && event.shiftKey && event.code === "KeyV") {
|
||||
if (!navigator.clipboard) return;
|
||||
navigator.clipboard
|
||||
.readText()
|
||||
.then(stringifiedPastedElement => {
|
||||
const pastedElement = JSON.parse(stringifiedPastedElement);
|
||||
const pastedElement = JSON.parse(COPIED_STYLES);
|
||||
if (pastedElement.type) {
|
||||
const {
|
||||
strokeColor,
|
||||
strokeWidth,
|
||||
backgroundColor,
|
||||
fillStyle,
|
||||
opacity
|
||||
} = pastedElement;
|
||||
elements.forEach(element => {
|
||||
if (element.isSelected) {
|
||||
element.backgroundColor = backgroundColor;
|
||||
element.strokeWidth = strokeWidth;
|
||||
element.strokeColor = strokeColor;
|
||||
element.fillStyle = fillStyle;
|
||||
element.opacity = opacity;
|
||||
element.backgroundColor = pastedElement?.backgroundColor;
|
||||
element.strokeWidth = pastedElement?.strokeWidth;
|
||||
element.strokeColor = pastedElement?.strokeColor;
|
||||
element.fillStyle = pastedElement?.fillStyle;
|
||||
element.opacity = pastedElement?.opacity;
|
||||
generateDraw(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.forceUpdate();
|
||||
event.preventDefault();
|
||||
})
|
||||
.catch(err => alert("Failed to read shape style!"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue