Add selection copy paste shortcuts
This commit is contained in:
parent
b3fc7f9e1d
commit
23dd67c1a9
|
@ -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 (
|
||||
<MapMenu
|
||||
isOpen={isOpen}
|
||||
|
|
|
@ -29,6 +29,16 @@ function redo(event: KeyboardEvent): boolean {
|
|||
return (key === "z" || key === "Z") && (ctrlKey || metaKey) && shiftKey;
|
||||
}
|
||||
|
||||
function copy(event: KeyboardEvent): boolean {
|
||||
const { key, ctrlKey, metaKey, shiftKey } = event;
|
||||
return (key === "c" || key === "C") && (ctrlKey || metaKey) && !shiftKey;
|
||||
}
|
||||
|
||||
function paste(event: KeyboardEvent): boolean {
|
||||
const { key, ctrlKey, metaKey, shiftKey } = event;
|
||||
return (key === "v" || key === "V") && (ctrlKey || metaKey) && !shiftKey;
|
||||
}
|
||||
|
||||
function zoomIn(event: KeyboardEvent): boolean {
|
||||
const { key, ctrlKey, metaKey } = event;
|
||||
return (key === "=" || key === "+") && !ctrlKey && !metaKey;
|
||||
|
@ -89,6 +99,8 @@ const shortcuts: Record<string, Shortcut> = {
|
|||
// Common
|
||||
undo,
|
||||
redo,
|
||||
copy,
|
||||
paste,
|
||||
delete: ({ key }) => key === "Backspace" || key === "Delete",
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user