From 95c46451772b633af53df3a28a6e7137505a0228 Mon Sep 17 00:00:00 2001 From: Edouard Tabary Date: Thu, 2 Jan 2025 15:04:41 +0100 Subject: [PATCH 1/2] Fix to make Copy/Paste keyboard shortcuts working with useSelection --- src/selection/useSelection.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/selection/useSelection.ts b/src/selection/useSelection.ts index d87313d0..c6b18e4b 100644 --- a/src/selection/useSelection.ts +++ b/src/selection/useSelection.ts @@ -310,7 +310,7 @@ export const useSelection = ({ ); const onKeyDown = useCallback((event: KeyboardEvent) => { - const element = event.target as any; + const element = event.target as HTMLElement; const isSafe = element.tagName !== 'INPUT' && element.tagName !== 'SELECT' && @@ -318,8 +318,9 @@ export const useSelection = ({ !element.isContentEditable; const isMeta = event.metaKey || event.ctrlKey; + const isSystemShortcut = ['c', 'x', 'v'].includes(event.key.toLowerCase()); - if (isSafe && isMeta) { + if (isSafe && isMeta && !isSystemShortcut) { event.preventDefault(); setMetaKeyDown(true); } From 56a509d0a4d91ae85acba229bc7fc12aec0ed1ca Mon Sep 17 00:00:00 2001 From: Edouard Tabary Date: Mon, 6 Jan 2025 12:12:31 +0100 Subject: [PATCH 2/2] Removing the preventDefault instead --- src/selection/useSelection.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/selection/useSelection.ts b/src/selection/useSelection.ts index c6b18e4b..aef21eda 100644 --- a/src/selection/useSelection.ts +++ b/src/selection/useSelection.ts @@ -318,10 +318,8 @@ export const useSelection = ({ !element.isContentEditable; const isMeta = event.metaKey || event.ctrlKey; - const isSystemShortcut = ['c', 'x', 'v'].includes(event.key.toLowerCase()); - if (isSafe && isMeta && !isSystemShortcut) { - event.preventDefault(); + if (isSafe && isMeta) { setMetaKeyDown(true); } }, []);