diff --git a/src/components/ActiveConfirmDialog.tsx b/src/components/ActiveConfirmDialog.tsx index 3c79a519..44a26e9a 100644 --- a/src/components/ActiveConfirmDialog.tsx +++ b/src/components/ActiveConfirmDialog.tsx @@ -1,6 +1,7 @@ import { atom, useAtom } from "jotai"; import { actionClearCanvas } from "../actions"; import { t } from "../i18n"; +import { jotaiScope } from "../jotai"; import { useExcalidrawActionManager } from "./App"; import ConfirmDialog from "./ConfirmDialog"; @@ -9,6 +10,7 @@ export const activeConfirmDialogAtom = atom<"clearCanvas" | null>(null); export const ActiveConfirmDialog = () => { const [activeConfirmDialog, setActiveConfirmDialog] = useAtom( activeConfirmDialogAtom, + jotaiScope, ); const actionManager = useExcalidrawActionManager(); diff --git a/src/components/LibraryMenuHeaderContent.tsx b/src/components/LibraryMenuHeaderContent.tsx index 43ea9689..8e6b9352 100644 --- a/src/components/LibraryMenuHeaderContent.tsx +++ b/src/components/LibraryMenuHeaderContent.tsx @@ -48,6 +48,7 @@ export const LibraryMenuHeader: React.FC<{ const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope); const [isLibraryMenuOpen, setIsLibraryMenuOpen] = useAtom( isLibraryMenuOpenAtom, + jotaiScope, ); const renderRemoveLibAlert = useCallback(() => { const content = selectedItems.length diff --git a/src/tests/shortcuts.test.tsx b/src/tests/shortcuts.test.tsx new file mode 100644 index 00000000..e0b4fcc5 --- /dev/null +++ b/src/tests/shortcuts.test.tsx @@ -0,0 +1,30 @@ +import { KEYS } from "../keys"; +import { Excalidraw } from "../packages/excalidraw/entry"; +import { API } from "./helpers/api"; +import { Keyboard } from "./helpers/ui"; +import { fireEvent, render, waitFor } from "./test-utils"; + +describe("shortcuts", () => { + it("Clear canvas shortcut should display confirm dialog", async () => { + await render( + , + ); + + expect(window.h.elements.length).toBe(1); + + Keyboard.withModifierKeys({ ctrl: true }, () => { + Keyboard.keyDown(KEYS.DELETE); + }); + const confirmDialog = document.querySelector(".confirm-dialog")!; + expect(confirmDialog).not.toBe(null); + + fireEvent.click(confirmDialog.querySelector('[aria-label="Confirm"]')!); + + await waitFor(() => { + expect(window.h.elements[0].isDeleted).toBe(true); + }); + }); +});