Let the native clipboard through where the canvas has nothing to copy

A bound chord used to be `preventDefault`ed before its handler ran, so the
canvas took every ⌘C and ⌘V whether or not the node clipboard would act —
which is what blocked copying selected text out of the chrome floating over
the canvas. A binding may now return `false` to decline the key; ⌘C does so
when there is a text selection or no node selected, ⌘V when nothing of ours
is stored.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CL9zvnnvcp1mvA8o7impxk
This commit is contained in:
2026-09-06 18:16:17 +02:00
co-authored by Claude Opus 5
parent 794b296fc1
commit 39c231d6f7
3 changed files with 115 additions and 4 deletions
+6 -2
View File
@@ -6,8 +6,12 @@ import { useEffect, useRef } from "react"
* A chord reads as `mod+shift+z`, where `mod` is ⌘ on a Mac and Ctrl
* everywhere else. Bindings are plain data, so a view declares the whole set
* it answers to in one place.
*
* A binding that returns `false` declines the key: it did nothing, so the
* browser's own default runs. That is how ⌘C stays a native copy whenever the
* canvas has nothing of its own to copy.
*/
export type Shortcuts = Record<string, (event: KeyboardEvent) => void>
export type Shortcuts = Record<string, (event: KeyboardEvent) => unknown>
/** Text fields and the code editor keep their own bindings and their own undo. */
export function isTextEntry(target: EventTarget | null): boolean {
@@ -55,8 +59,8 @@ export function useShortcuts(bindings: Shortcuts, inTextEntry: string[] = []) {
) {
return
}
if (run(event) === false) return
event.preventDefault()
run(event)
}
window.addEventListener("keydown", onKeyDown)
return () => window.removeEventListener("keydown", onKeyDown)