From 11e2f90ca1d726e609ece695f21a001ccb3b19cb Mon Sep 17 00:00:00 2001 From: Jang Min Date: Sat, 4 Feb 2023 21:33:40 +0900 Subject: [PATCH] feat: shortcut for clearCanvas confirmDialog (#6114) Co-authored-by: dwelle resolve https://github.com/excalidraw/excalidraw/issues/5818 --- src/actions/actionDeleteSelected.tsx | 4 ++- src/actions/shortcuts.ts | 2 ++ src/components/App.tsx | 10 ++++++- src/components/HelpDialog.tsx | 44 +++++++++++++++------------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/actions/actionDeleteSelected.tsx b/src/actions/actionDeleteSelected.tsx index a1820a33..86b98528 100644 --- a/src/actions/actionDeleteSelected.tsx +++ b/src/actions/actionDeleteSelected.tsx @@ -154,7 +154,9 @@ export const actionDeleteSelected = register({ }; }, contextItemLabel: "labels.delete", - keyTest: (event) => event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE, + keyTest: (event, appState, elements) => + (event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE) && + !event[KEYS.CTRL_OR_CMD], PanelComponent: ({ elements, appState, updateData }) => ( = { toggleTheme: [getShortcutKey("Shift+Alt+D")], saveScene: [getShortcutKey("CtrlOrCmd+S")], loadScene: [getShortcutKey("CtrlOrCmd+O")], + clearCanvas: [getShortcutKey("CtrlOrCmd+Delete")], imageExport: [getShortcutKey("CtrlOrCmd+Shift+E")], cut: [getShortcutKey("CtrlOrCmd+X")], copy: [getShortcutKey("CtrlOrCmd+C")], diff --git a/src/components/App.tsx b/src/components/App.tsx index 7b2b5e40..f01faa27 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -279,6 +279,8 @@ import { shouldShowBoundingBox } from "../element/transformHandles"; import { Fonts } from "../scene/Fonts"; import { actionPaste } from "../actions/actionClipboard"; import { actionToggleHandTool } from "../actions/actionCanvas"; +import { jotaiStore } from "../jotai"; +import { activeConfirmDialogAtom } from "./ActiveConfirmDialog"; const deviceContextInitialValue = { isSmScreen: false, @@ -1952,7 +1954,6 @@ class App extends React.Component { ); // Input handling - private onKeyDown = withBatchedUpdates( (event: React.KeyboardEvent | KeyboardEvent) => { // normalize `event.key` when CapsLock is pressed #2372 @@ -2194,6 +2195,13 @@ class App extends React.Component { event.stopPropagation(); } } + + if ( + event[KEYS.CTRL_OR_CMD] && + (event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE) + ) { + jotaiStore.set(activeConfirmDialogAtom, "clearCanvas"); + } }, ); diff --git a/src/components/HelpDialog.tsx b/src/components/HelpDialog.tsx index 69f3e6a5..8cb775fc 100644 --- a/src/components/HelpDialog.tsx +++ b/src/components/HelpDialog.tsx @@ -273,22 +273,6 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => { className="HelpDialog__island--editor" caption={t("helpDialog.editor")} > - - - - void }) => { ]} isOr={true} /> + + void }) => { label={t("labels.pasteAsPlaintext")} shortcuts={[getShortcutKey("CtrlOrCmd+Shift+V")]} /> + + + + {/* firefox supports clipboard API under a flag, so we'll show users what they can do in the error message */} {(probablySupportsClipboardBlob || isFirefox) && ( @@ -329,10 +337,6 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => { label={t("labels.pasteStyles")} shortcuts={[getShortcutKey("CtrlOrCmd+Alt+V")]} /> -