From 2ad0716f3d0894e4ac1a115de3c81629e0d31324 Mon Sep 17 00:00:00 2001 From: Faustino Kialungila Date: Mon, 24 Feb 2020 15:21:13 +0100 Subject: [PATCH] fix style pasting (#832) * fix style pasting * Update src/actions/actionStyles.ts --- src/actions/actionStyles.ts | 9 ++++++++- src/element/index.ts | 2 +- src/element/typeChecks.ts | 11 +++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/actions/actionStyles.ts b/src/actions/actionStyles.ts index aa1faf60..079412f4 100644 --- a/src/actions/actionStyles.ts +++ b/src/actions/actionStyles.ts @@ -1,5 +1,9 @@ import { Action } from "./types"; -import { isTextElement, redrawTextBoundingBox } from "../element"; +import { + isTextElement, + isExcalidrawElement, + redrawTextBoundingBox, +} from "../element"; import { KEYS } from "../keys"; let copiedStyles: string = "{}"; @@ -22,6 +26,9 @@ export const actionPasteStyles: Action = { name: "pasteStyles", perform: elements => { const pastedElement = JSON.parse(copiedStyles); + if (!isExcalidrawElement(pastedElement)) { + return { elements }; + } return { elements: elements.map(element => { if (element.isSelected) { diff --git a/src/element/index.ts b/src/element/index.ts index bc696734..f3beecbd 100644 --- a/src/element/index.ts +++ b/src/element/index.ts @@ -14,7 +14,7 @@ export { getCursorForResizingElement, normalizeResizeHandle, } from "./resizeTest"; -export { isTextElement } from "./typeChecks"; +export { isTextElement, isExcalidrawElement } from "./typeChecks"; export { textWysiwyg } from "./textWysiwyg"; export { redrawTextBoundingBox } from "./textElement"; export { diff --git a/src/element/typeChecks.ts b/src/element/typeChecks.ts index 4fbde9ad..d6399d48 100644 --- a/src/element/typeChecks.ts +++ b/src/element/typeChecks.ts @@ -5,3 +5,14 @@ export function isTextElement( ): element is ExcalidrawTextElement { 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" + ); +}