fix style pasting (#832)
* fix style pasting * Update src/actions/actionStyles.ts
This commit is contained in:
parent
fbab93baff
commit
2ad0716f3d
@ -1,5 +1,9 @@
|
|||||||
import { Action } from "./types";
|
import { Action } from "./types";
|
||||||
import { isTextElement, redrawTextBoundingBox } from "../element";
|
import {
|
||||||
|
isTextElement,
|
||||||
|
isExcalidrawElement,
|
||||||
|
redrawTextBoundingBox,
|
||||||
|
} from "../element";
|
||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
|
|
||||||
let copiedStyles: string = "{}";
|
let copiedStyles: string = "{}";
|
||||||
@ -22,6 +26,9 @@ export const actionPasteStyles: Action = {
|
|||||||
name: "pasteStyles",
|
name: "pasteStyles",
|
||||||
perform: elements => {
|
perform: elements => {
|
||||||
const pastedElement = JSON.parse(copiedStyles);
|
const pastedElement = JSON.parse(copiedStyles);
|
||||||
|
if (!isExcalidrawElement(pastedElement)) {
|
||||||
|
return { elements };
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
elements: elements.map(element => {
|
elements: elements.map(element => {
|
||||||
if (element.isSelected) {
|
if (element.isSelected) {
|
||||||
|
@ -14,7 +14,7 @@ export {
|
|||||||
getCursorForResizingElement,
|
getCursorForResizingElement,
|
||||||
normalizeResizeHandle,
|
normalizeResizeHandle,
|
||||||
} from "./resizeTest";
|
} from "./resizeTest";
|
||||||
export { isTextElement } from "./typeChecks";
|
export { isTextElement, isExcalidrawElement } from "./typeChecks";
|
||||||
export { textWysiwyg } from "./textWysiwyg";
|
export { textWysiwyg } from "./textWysiwyg";
|
||||||
export { redrawTextBoundingBox } from "./textElement";
|
export { redrawTextBoundingBox } from "./textElement";
|
||||||
export {
|
export {
|
||||||
|
@ -5,3 +5,14 @@ export function isTextElement(
|
|||||||
): element is ExcalidrawTextElement {
|
): element is ExcalidrawTextElement {
|
||||||
return element.type === "text";
|
return element.type === "text";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isExcalidrawElement(element: any): boolean {
|
||||||
|
return (
|
||||||
|
element?.type === "text" ||
|
||||||
|
element?.type === "diamond" ||
|
||||||
|
element?.type === "rectangle" ||
|
||||||
|
element?.type === "ellipse" ||
|
||||||
|
element?.type === "arrow" ||
|
||||||
|
element?.type === "line"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user