Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

refactor: remove duplicate key handling (#2878)

David Luzar6abf4f52ff39
diff --git a/src/actions/actionClipboard.tsx b/src/actions/actionClipboard.tsx
index 727fab2892..70e4af17d5 100644
--- a/src/actions/actionClipboard.tsx
+++ b/src/actions/actionClipboard.tsx
@@ -5,6 +5,7 @@ import { actionDeleteSelected } from "./actionDeleteSelected";
import { getSelectedElements } from "../scene/selection";
import { exportCanvas } from "../data/index";
import { getNonDeletedElements } from "../element";
+import { t } from "../i18n";
export const actionCopy = register({
name: "copy",
@@ -91,6 +92,10 @@ export const actionCopyAsPng = register({
appState,
);
return {
+ appState: {
+ ...appState,
+ toastMessage: t("toast.copyToClipboardAsPng"),
+ },
commitToHistory: false,
};
} catch (error) {
@@ -105,4 +110,5 @@ export const actionCopyAsPng = register({
}
},
contextItemLabel: "labels.copyAsPng",
+ keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey,
});
diff --git a/src/components/App.tsx b/src/components/App.tsx
index 795d2defb1..784916c226 100644
--- a/src/components/App.tsx
+++ b/src/components/App.tsx
@@ -53,7 +53,7 @@ import {
TEXT_TO_CENTER_SNAP_THRESHOLD,
TOUCH_CTX_MENU_TIMEOUT,
} from "../constants";
-import { exportCanvas, loadFromBlob } from "../data";
+import { loadFromBlob } from "../data";
import { isValidLibrary } from "../data/json";
import { Library } from "../data/library";
import { restore } from "../data/restore";
@@ -929,25 +929,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
copyToClipboard(this.scene.getElements(), this.state);
};
- private copyToClipboardAsPng = async () => {
- const elements = this.scene.getElements();
-
- const selectedElements = getSelectedElements(elements, this.state);
- try {
- await exportCanvas(
- "clipboard",
- selectedElements.length ? selectedElements : elements,
- this.state,
- this.canvas!,
- this.state,
- );
- this.setState({ toastMessage: t("toast.copyToClipboardAsPng") });
- } catch (error) {
- console.error(error);
- this.setState({ errorMessage: error.message });
- }
- };
-
private static resetTapTwice() {
didTapTwice = false;
}
@@ -1251,22 +1232,10 @@ class App extends React.Component<ExcalidrawProps, AppState> {
});
}
- if (!event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.Z) {
- this.toggleZenMode();
- }
- if (event[KEYS.CTRL_OR_CMD] && event.code === CODES.QUOTE) {
- this.toggleGridMode();
- }
if (event[KEYS.CTRL_OR_CMD]) {
this.setState({ isBindingEnabled: false });
}
- if (event.code === CODES.C && event.altKey && event.shiftKey) {
- this.copyToClipboardAsPng();
- event.preventDefault();
- return;
- }
-
if (this.actionManager.handleKeyDown(event)) {
return;
}