Add Cut to menus (#2511)

Co-authored-by: Zen Tang <zen@wayve.ai>
This commit is contained in:
Zen Tang 2020-12-12 05:54:34 -06:00 committed by GitHub
parent ae15380a9f
commit 1a134a88bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View File

@ -873,8 +873,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
if (isWritableElement(event.target)) {
return;
}
this.copyAll();
this.actionManager.executeAction(actionDeleteSelected);
this.cutAll();
event.preventDefault();
});
@ -886,6 +885,11 @@ class App extends React.Component<ExcalidrawProps, AppState> {
event.preventDefault();
});
private cutAll = () => {
this.copyAll();
this.actionManager.executeAction(actionDeleteSelected);
};
private copyAll = () => {
copyToClipboard(this.scene.getElements(), this.state);
};
@ -3621,6 +3625,10 @@ class App extends React.Component<ExcalidrawProps, AppState> {
ContextMenu.push({
options: [
{
label: t("labels.cut"),
action: this.cutAll,
},
navigator.clipboard && {
label: t("labels.copy"),
action: this.copyAll,

View File

@ -240,6 +240,10 @@ export const ShortcutsDialog = ({ onClose }: { onClose?: () => void }) => {
]}
isOr={true}
/>
<Shortcut
label={t("labels.cut")}
shortcuts={[getShortcutKey("CtrlOrCmd+X")]}
/>
<Shortcut
label={t("labels.copy")}
shortcuts={[getShortcutKey("CtrlOrCmd+C")]}

View File

@ -4,6 +4,7 @@
"selectAll": "Select all",
"multiSelect": "Add element to selection",
"moveCanvas": "Move canvas",
"cut": "Cut",
"copy": "Copy",
"copyAsPng": "Copy to clipboard as PNG",
"copyAsSvg": "Copy to clipboard as SVG",

View File

@ -657,6 +657,7 @@ describe("regression tests", () => {
const contextMenu = document.querySelector(".context-menu");
const options = contextMenu?.querySelectorAll(".context-menu-option");
const expectedOptions = [
"Cut",
"Copy styles",
"Paste styles",
"Delete",
@ -669,7 +670,7 @@ describe("regression tests", () => {
];
expect(contextMenu).not.toBeNull();
expect(contextMenu?.children.length).toBe(9);
expect(contextMenu?.children.length).toBe(10);
options?.forEach((opt, i) => {
expect(opt.textContent).toBe(expectedOptions[i]);
});
@ -699,6 +700,7 @@ describe("regression tests", () => {
const contextMenu = document.querySelector(".context-menu");
const options = contextMenu?.querySelectorAll(".context-menu-option");
const expectedOptions = [
"Cut",
"Copy styles",
"Paste styles",
"Delete",
@ -712,7 +714,7 @@ describe("regression tests", () => {
];
expect(contextMenu).not.toBeNull();
expect(contextMenu?.children.length).toBe(10);
expect(contextMenu?.children.length).toBe(11);
options?.forEach((opt, i) => {
expect(opt.textContent).toBe(expectedOptions[i]);
});
@ -746,6 +748,7 @@ describe("regression tests", () => {
const contextMenu = document.querySelector(".context-menu");
const options = contextMenu?.querySelectorAll(".context-menu-option");
const expectedOptions = [
"Cut",
"Copy styles",
"Paste styles",
"Delete",
@ -759,7 +762,7 @@ describe("regression tests", () => {
];
expect(contextMenu).not.toBeNull();
expect(contextMenu?.children.length).toBe(10);
expect(contextMenu?.children.length).toBe(11);
options?.forEach((opt, i) => {
expect(opt.textContent).toBe(expectedOptions[i]);
});