fix: more copyText fixes (#5016)
This commit is contained in:
parent
89471094ce
commit
77d789ed8e
@ -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",
|
||||
});
|
||||
|
@ -75,7 +75,7 @@ export {
|
||||
actionCut,
|
||||
actionCopyAsPng,
|
||||
actionCopyAsSvg,
|
||||
copyAllTextNodesAsText,
|
||||
copyText,
|
||||
} from "./actionClipboard";
|
||||
|
||||
export { actionToggleGridMode } from "./actionToggleGridMode";
|
||||
|
@ -41,7 +41,7 @@ export type ActionName =
|
||||
| "paste"
|
||||
| "copyAsPng"
|
||||
| "copyAsSvg"
|
||||
| "copyAllTextNodesAsText"
|
||||
| "copyText"
|
||||
| "sendBackward"
|
||||
| "bringForward"
|
||||
| "sendToBack"
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user