Skip to content

Commit

Permalink
fix: only show the option for text elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fausto95 committed Apr 5, 2022
1 parent 8bd03a1 commit 0fd42c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/actions/actionClipboard.tsx
Expand Up @@ -4,7 +4,7 @@ import { copyTextToSystemClipboard, copyToClipboard } from "../clipboard";
import { actionDeleteSelected } from "./actionDeleteSelected";
import { getSelectedElements } from "../scene/selection";
import { exportCanvas } from "../data/index";
import { getNonDeletedElements, isTextElement } from "../element";
import { getNonDeletedElements } from "../element";
import { t } from "../i18n";
import { ExcalidrawTextElement } from "../element/types";

Expand Down Expand Up @@ -132,15 +132,10 @@ export const copyAllTextNodesAsText = register({
name: "copyAllTextNodesAsText",
trackEvent: { category: "element" },
perform: (elements) => {
const isTextNodesOnly = getNonDeletedElements(elements).every((element) =>
isTextElement(element),
);
if (isTextNodesOnly) {
const text = (
getNonDeletedElements(elements) as ExcalidrawTextElement[]
).reduce((acc, element) => `${acc}${element.text}\n`, "");
copyTextToSystemClipboard(text);
}
const text = (
getNonDeletedElements(elements) as ExcalidrawTextElement[]
).reduce((acc, element) => `${acc}${element.text}\n`, "");
copyTextToSystemClipboard(text);
return {
commitToHistory: false,
};
Expand Down
9 changes: 8 additions & 1 deletion src/components/App.tsx
Expand Up @@ -5476,6 +5476,8 @@ class App extends React.Component<AppProps, AppState> {

const elements = this.scene.getElements();

const isTextNodesOnly = elements.every((element) => isTextElement(element));

const options: ContextMenuOption[] = [];
if (probablySupportsClipboardBlob && elements.length > 0) {
options.push(actionCopyAsPng);
Expand All @@ -5485,7 +5487,11 @@ class App extends React.Component<AppProps, AppState> {
options.push(actionCopyAsSvg);
}

if (probablySupportsClipboardWriteText && elements.length > 0) {
if (
probablySupportsClipboardWriteText &&
elements.length > 0 &&
isTextNodesOnly
) {
options.push(copyAllTextNodesAsText);
}
if (type === "canvas") {
Expand Down Expand Up @@ -5533,6 +5539,7 @@ class App extends React.Component<AppProps, AppState> {
actionCopyAsSvg,
probablySupportsClipboardWriteText &&
elements.length > 0 &&
isTextNodesOnly &&
copyAllTextNodesAsText,
((probablySupportsClipboardBlob && elements.length > 0) ||
(probablySupportsClipboardWriteText && elements.length > 0)) &&
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.json
Expand Up @@ -9,7 +9,7 @@
"copy": "Copy",
"copyAsPng": "Copy to clipboard as PNG",
"copyAsSvg": "Copy to clipboard as SVG",
"copyAllTextNodesAsText": "Copy to clipboard all nodes as text",
"copyAllTextNodesAsText": "Copy to clipboard as a single text element",
"bringForward": "Bring forward",
"sendToBack": "Send to back",
"bringToFront": "Bring to front",
Expand Down

0 comments on commit 0fd42c9

Please sign in to comment.