6421306849
The context menu advertised Ctrl+C/Ctrl+V hints but useKeyboardShortcuts only handled undo/redo/delete/duplicate/escape -- pressing them did nothing. Add a tiny shared module-level clipboard (src/hooks/clipboard.ts) used by both the keyboard hook and the context menu so copying via one entry point and pasting via the other stay consistent. Ctrl/Cmd+C stores the selected node id (skipping ROOT). Ctrl/Cmd+V inserts a copy as a sibling of the current selection via regenerateTreeIds, mirroring the existing context-menu paste behavior. Both respect the existing "disabled while typing" guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
24 lines
949 B
TypeScript
24 lines
949 B
TypeScript
/**
|
|
* Tiny shared clipboard for canvas node copy/paste.
|
|
*
|
|
* Both the context menu (right-click Copy/Paste) and the keyboard shortcuts
|
|
* hook (Ctrl/Cmd+C / Ctrl/Cmd+V) read and write this single module-level
|
|
* store, so copying a node via one entry point and pasting via the other
|
|
* behaves consistently instead of each maintaining its own clipboard.
|
|
*
|
|
* Deliberately not React state -- nothing in the UI needs to re-render
|
|
* reactively when the clipboard changes; consumers just read the current
|
|
* value at the moment they need it (on paste, or when a menu opens).
|
|
*/
|
|
let clipboardNodeId: string | null = null;
|
|
|
|
/** Returns the id of the node currently on the clipboard, or null if empty. */
|
|
export function getClipboardNodeId(): string | null {
|
|
return clipboardNodeId;
|
|
}
|
|
|
|
/** Sets (or clears, with `null`) the node id on the clipboard. */
|
|
export function setClipboardNodeId(nodeId: string | null): void {
|
|
clipboardNodeId = nodeId;
|
|
}
|