-
In #6849, Kamil figured out how to add a button that (when clicked) would push content to the clipboard. The relevant part was as simple as: const newAnchor = document.createElement("a");
newAnchor.dataset.clipboardText = site_url + location.pathname; It seems this is somehow leveraging clipboard.js which I think is already initialized in mkdocs-material, presumably to handle all the copy-to-clipboard features (code blocks and search). What I'd like to do is add a keyboard shortcut that pushes content to the clipboard in the same way, but I haven't been able to figure much of anything out. Here's what I tried: keyboard$.subscribe(function(key) {
if (key.mode === "global" && key.type === "l") {
clipboardText = site_url + location.pathname + location.hash;
key.claim()
}
}) It was a shot in the dark based on the Any help would be most appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Clipboard.js works declaratively, so what the second line in Kamil's code does is to create a I could not find anything on how to use keyboard events with clipboard.js. Do you have a UI element that does the clipboard action? Is so, you might be able to trigger it programmatically from your keyboard event handler. |
Beta Was this translation helpful? Give feedback.
-
PS: Meta question about ettiquette for you @alexvoss : I'm not sure whether it's appropriate for me to mark the final result (my last comment) as the answer (that's my inclination, in order to help posterity) or whether it's more important to give credit for inspiration & guidance and thus mark your first post as the answer...? |
Beta Was this translation helpful? Give feedback.
OH MY GOARSH! I can't believe it's this simple.