Virtual whiteboard for sketching hand-drawn like diagrams
fix: more copyText fixes (#5016)
David Luzar77d789ed8e68
diff --git a/src/actions/actionClipboard.tsx b/src/actions/actionClipboard.tsxindex 473c56e32f..5d92290e21 100644--- a/src/actions/actionClipboard.tsx+++ b/src/actions/actionClipboard.tsx@@ -1,6 +1,10 @@import { CODES, KEYS } from "../keys";import { register } from "./register";-import { copyTextToSystemClipboard, copyToClipboard } from "../clipboard";+import {+ copyTextToSystemClipboard,+ copyToClipboard,+ probablySupportsClipboardWriteText,+} from "../clipboard";import { actionDeleteSelected } from "./actionDeleteSelected";import { getSelectedElements } from "../scene/selection";import { exportCanvas } from "../data/index";@@ -127,8 +131,8 @@ export const actionCopyAsPng = register({keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey,});-export const copyAllTextNodesAsText = register({- name: "copyAllTextNodesAsText",+export const copyText = register({+ name: "copyText",trackEvent: { category: "element" },perform: (elements, appState) => {const selectedElements = getSelectedElements(@@ -137,16 +141,24 @@ export const copyAllTextNodesAsText = register({true,);- const text = selectedElements.reduce((acc, element) => {- if (isTextElement(element)) {- return `${acc}${element.text}\n\n`;- }- return acc;- }, "");+ const text = selectedElements+ .reduce((acc: string[], element) => {+ if (isTextElement(element)) {+ acc.push(element.text);+ }+ return acc;+ }, [])+ .join("\n\n");copyTextToSystemClipboard(text);return {commitToHistory: false,};},- contextItemLabel: "labels.copyAllTextNodesAsText",+ contextItemPredicate: (elements, appState) => {+ return (+ probablySupportsClipboardWriteText &&+ getSelectedElements(elements, appState, true).some(isTextElement)+ );+ },+ contextItemLabel: "labels.copyText",});diff --git a/src/actions/index.ts b/src/actions/index.tsindex 34f8421089..ffb20bc3f3 100644--- a/src/actions/index.ts+++ b/src/actions/index.ts@@ -75,7 +75,7 @@ export {actionCut,actionCopyAsPng,actionCopyAsSvg,- copyAllTextNodesAsText,+ copyText,} from "./actionClipboard";export { actionToggleGridMode } from "./actionToggleGridMode";diff --git a/src/actions/types.ts b/src/actions/types.tsindex fe6044a362..810f69c157 100644--- a/src/actions/types.ts+++ b/src/actions/types.ts@@ -41,7 +41,7 @@ export type ActionName =| "paste"| "copyAsPng"| "copyAsSvg"- | "copyAllTextNodesAsText"+ | "copyText"| "sendBackward"| "bringForward"| "sendToBack"diff --git a/src/components/App.tsx b/src/components/App.tsxindex c9a141f39c..6aaca20187 100644--- a/src/components/App.tsx+++ b/src/components/App.tsx@@ -11,7 +11,7 @@ import {actionCopy,actionCopyAsPng,actionCopyAsSvg,- copyAllTextNodesAsText,+ copyText,actionCopyStyles,actionCut,actionDeleteSelected,@@ -5490,8 +5490,12 @@ class App extends React.Component<AppProps, AppState> {options.push(actionCopyAsSvg);}- if (probablySupportsClipboardWriteText && selectedElements.length > 0) {- options.push(copyAllTextNodesAsText);+ if (+ type === "element" &&+ copyText.contextItemPredicate(elements, this.state) &&+ probablySupportsClipboardWriteText+ ) {+ options.push(copyText);}if (type === "canvas") {const viewModeOptions = [@@ -5538,7 +5542,7 @@ class App extends React.Component<AppProps, AppState> {actionCopyAsSvg,probablySupportsClipboardWriteText &&selectedElements.length > 0 &&- copyAllTextNodesAsText,+ copyText,((probablySupportsClipboardBlob && elements.length > 0) ||(probablySupportsClipboardWriteText && elements.length > 0)) &&separator,diff --git a/src/locales/en.json b/src/locales/en.jsonindex 08eef15cec..5bcaa850ae 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -9,7 +9,7 @@"copy": "Copy","copyAsPng": "Copy to clipboard as PNG","copyAsSvg": "Copy to clipboard as SVG",- "copyAllTextNodesAsText": "Copy to clipboard as a single text element",+ "copyText": "Copy to clipboard as text","bringForward": "Bring forward","sendToBack": "Send to back","bringToFront": "Bring to front",