fix: more copyText fixes (#5016)
This commit is contained in:
parent
89471094ce
commit
77d789ed8e
@ -1,6 +1,10 @@
|
|||||||
import { CODES, KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
import { copyTextToSystemClipboard, copyToClipboard } from "../clipboard";
|
import {
|
||||||
|
copyTextToSystemClipboard,
|
||||||
|
copyToClipboard,
|
||||||
|
probablySupportsClipboardWriteText,
|
||||||
|
} from "../clipboard";
|
||||||
import { actionDeleteSelected } from "./actionDeleteSelected";
|
import { actionDeleteSelected } from "./actionDeleteSelected";
|
||||||
import { getSelectedElements } from "../scene/selection";
|
import { getSelectedElements } from "../scene/selection";
|
||||||
import { exportCanvas } from "../data/index";
|
import { exportCanvas } from "../data/index";
|
||||||
@ -127,8 +131,8 @@ export const actionCopyAsPng = register({
|
|||||||
keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey,
|
keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const copyAllTextNodesAsText = register({
|
export const copyText = register({
|
||||||
name: "copyAllTextNodesAsText",
|
name: "copyText",
|
||||||
trackEvent: { category: "element" },
|
trackEvent: { category: "element" },
|
||||||
perform: (elements, appState) => {
|
perform: (elements, appState) => {
|
||||||
const selectedElements = getSelectedElements(
|
const selectedElements = getSelectedElements(
|
||||||
@ -137,16 +141,24 @@ export const copyAllTextNodesAsText = register({
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
const text = selectedElements.reduce((acc, element) => {
|
const text = selectedElements
|
||||||
|
.reduce((acc: string[], element) => {
|
||||||
if (isTextElement(element)) {
|
if (isTextElement(element)) {
|
||||||
return `${acc}${element.text}\n\n`;
|
acc.push(element.text);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, "");
|
}, [])
|
||||||
|
.join("\n\n");
|
||||||
copyTextToSystemClipboard(text);
|
copyTextToSystemClipboard(text);
|
||||||
return {
|
return {
|
||||||
commitToHistory: false,
|
commitToHistory: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
contextItemLabel: "labels.copyAllTextNodesAsText",
|
contextItemPredicate: (elements, appState) => {
|
||||||
|
return (
|
||||||
|
probablySupportsClipboardWriteText &&
|
||||||
|
getSelectedElements(elements, appState, true).some(isTextElement)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
contextItemLabel: "labels.copyText",
|
||||||
});
|
});
|
||||||
|
@ -75,7 +75,7 @@ export {
|
|||||||
actionCut,
|
actionCut,
|
||||||
actionCopyAsPng,
|
actionCopyAsPng,
|
||||||
actionCopyAsSvg,
|
actionCopyAsSvg,
|
||||||
copyAllTextNodesAsText,
|
copyText,
|
||||||
} from "./actionClipboard";
|
} from "./actionClipboard";
|
||||||
|
|
||||||
export { actionToggleGridMode } from "./actionToggleGridMode";
|
export { actionToggleGridMode } from "./actionToggleGridMode";
|
||||||
|
@ -41,7 +41,7 @@ export type ActionName =
|
|||||||
| "paste"
|
| "paste"
|
||||||
| "copyAsPng"
|
| "copyAsPng"
|
||||||
| "copyAsSvg"
|
| "copyAsSvg"
|
||||||
| "copyAllTextNodesAsText"
|
| "copyText"
|
||||||
| "sendBackward"
|
| "sendBackward"
|
||||||
| "bringForward"
|
| "bringForward"
|
||||||
| "sendToBack"
|
| "sendToBack"
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
actionCopy,
|
actionCopy,
|
||||||
actionCopyAsPng,
|
actionCopyAsPng,
|
||||||
actionCopyAsSvg,
|
actionCopyAsSvg,
|
||||||
copyAllTextNodesAsText,
|
copyText,
|
||||||
actionCopyStyles,
|
actionCopyStyles,
|
||||||
actionCut,
|
actionCut,
|
||||||
actionDeleteSelected,
|
actionDeleteSelected,
|
||||||
@ -5490,8 +5490,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
options.push(actionCopyAsSvg);
|
options.push(actionCopyAsSvg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (probablySupportsClipboardWriteText && selectedElements.length > 0) {
|
if (
|
||||||
options.push(copyAllTextNodesAsText);
|
type === "element" &&
|
||||||
|
copyText.contextItemPredicate(elements, this.state) &&
|
||||||
|
probablySupportsClipboardWriteText
|
||||||
|
) {
|
||||||
|
options.push(copyText);
|
||||||
}
|
}
|
||||||
if (type === "canvas") {
|
if (type === "canvas") {
|
||||||
const viewModeOptions = [
|
const viewModeOptions = [
|
||||||
@ -5538,7 +5542,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
actionCopyAsSvg,
|
actionCopyAsSvg,
|
||||||
probablySupportsClipboardWriteText &&
|
probablySupportsClipboardWriteText &&
|
||||||
selectedElements.length > 0 &&
|
selectedElements.length > 0 &&
|
||||||
copyAllTextNodesAsText,
|
copyText,
|
||||||
((probablySupportsClipboardBlob && elements.length > 0) ||
|
((probablySupportsClipboardBlob && elements.length > 0) ||
|
||||||
(probablySupportsClipboardWriteText && elements.length > 0)) &&
|
(probablySupportsClipboardWriteText && elements.length > 0)) &&
|
||||||
separator,
|
separator,
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"copy": "Copy",
|
"copy": "Copy",
|
||||||
"copyAsPng": "Copy to clipboard as PNG",
|
"copyAsPng": "Copy to clipboard as PNG",
|
||||||
"copyAsSvg": "Copy to clipboard as SVG",
|
"copyAsSvg": "Copy to clipboard as SVG",
|
||||||
"copyAllTextNodesAsText": "Copy to clipboard as a single text element",
|
"copyText": "Copy to clipboard as text",
|
||||||
"bringForward": "Bring forward",
|
"bringForward": "Bring forward",
|
||||||
"sendToBack": "Send to back",
|
"sendToBack": "Send to back",
|
||||||
"bringToFront": "Bring to front",
|
"bringToFront": "Bring to front",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user