-
-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Is your feature request related to a problem? Please describe.
This may just be me not knowing how to implement the feature. I've tried implementing copy/cut/paste feature via custom hotkeys but can't get the handler to fire (details below). The issue is specifically tied to using the typical hotkeys (I tried a few different things including Meta+KeyC). With other hotkeys (for example, just KeyC I can get the handlers to fire)
Describe the solution you'd like
This seems like it might be a pretty common feature that people would want. I would expect:
- A
copyPasteFeaturethat can be optionally added to the list of features passed in touseTree. onCopy,onCut, andonPastehooks made available in the object passed intouseTree(only used when feature is included)"copyItems","cutItems", and"pasteItems"as native hotkey actions that are properly linked up to everything else.- [opt]: imperative functions that make the copy/cut/paste calls on the tree (i.e.
tree.copySelectedItems(),tree.cutSelectedItems,treePasteItems- naming I'm not set on)
Internally, whatever is needed to properly handle taking control of the standard hotkeys would be implemented and whatever needed would be passed through via tree.getContainerProps().
Describe alternatives you've considered
I tried implementing this myself with custom hotkeys but wasn't able to get the handler to fire. I think the issue is with browsers intercepting the standard cut/copy/paste commands?
Here is an example of what I tried:
const clipboardRef = useRef<{
items: ItemInstance<TreeNode>[];
cut: boolean;
} | null>(null);
const tree = useTree<TreeNode>({
...
hotkeys: {
customCopyItems: {
hotkey: "Meta+KeyC",
preventDefault: true,
isEnabled: (tree) => tree.getSelectedItems().length > 0,
handler: (_, tree) => {
console.log(
"copy",
tree.getSelectedItems().map((i) => i.getId())
);
clipboardRef.current = { items: tree.getSelectedItems(), cut: false };
},
},
},
})
I had a few attempts at trying to disable the browser copy/paste behavior on a container element but that didn't seem to work. That might still be the answer and maybe I just didn't quite get it right.