From 23dd67c1a9b3d921865cc323c3c48591304536a1 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 23 Jul 2021 15:53:13 +1000 Subject: [PATCH] Add selection copy paste shortcuts --- src/components/selection/SelectionMenu.tsx | 15 +++++++++++++++ src/shortcuts.ts | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/components/selection/SelectionMenu.tsx b/src/components/selection/SelectionMenu.tsx index 9128f42..8a690b3 100644 --- a/src/components/selection/SelectionMenu.tsx +++ b/src/components/selection/SelectionMenu.tsx @@ -32,6 +32,8 @@ import { MapState } from "../../types/MapState"; import { isMapState } from "../../validators/MapState"; import { isSelection } from "../../validators/Selection"; import { getRelativePointerPosition } from "../../helpers/konva"; +import { useKeyboard } from "../../contexts/KeyboardContext"; +import shortcuts from "../../shortcuts"; type SelectionMenuProps = { isOpen: boolean; @@ -346,6 +348,19 @@ function SelectionMenu({ } } + function handleKeyDown(event: KeyboardEvent) { + if (active) { + if (selection && shortcuts.copy(event)) { + handleCopy(); + } + if (shortcuts.paste(event)) { + handlePaste(); + } + } + } + + useKeyboard(handleKeyDown); + return ( = { // Common undo, redo, + copy, + paste, delete: ({ key }) => key === "Backspace" || key === "Delete", };