Closed glebsexy closed 2 months ago
Hey Gleb. Interesting. I had a little play around and I have a theory. I think Figma intercepts certain keyboard shortcuts and forwards them to the plugin window (or maybe to the editor). However because a server is used when developing, theses events aren't being aren't being passed to the server. I'm gonna try experimenting and see what more I can find.
Figma must implement its own event listeners, which are lost when the plugin is pointed to the dev server. So, to get around it, I can recreate them, including the keyboard shortcut to close the plugin, which I noticed also doesn't work. Expect a fix soon!
I did some more investigation. I'm pretty sure Figma adds its own event listener to the iframe that the plugin runs in as you can see they are attached to the document before redirecting to the dev server. Unfortunately, I couldn't find a way to copy or forward these event listeners to the new document created by the dev server. What I was able to do, though, was implement my own select all functionality when cmd/ctrl + a is pressed.
There's a minor issue with cmd + opt + p not working. Unfortunately, this one is harder to work around because I can't force a re-run. I can only show and hide the UI, which technically isn't the same thing. So, for now, I'll leave that one as is.
Let me know how you get on with this update in the latest release.
I have a hack for this use-case that I thought is completely useless. To relaunch the plugin — in the plugin UI call the following function:
window.parent.postMessage('$INTERNAL_DO_NOT_USE$RERUN_PLUGIN$', '*')
Here is a minimal proof of concept plugin:
Haha. Gleb! You mastermind! I'll give it a go!
It works. Thanks @glebsexy! 😍
Minor issue. I have a textarea element in my UI and while I use a dev server it doesn't seem to register Cmd + A to select all text in the textarea.
It only doesn't work in the Figma app, it works when viewing the UI in the browser. It also works fine after building the file for production
Haven't found any other shortcuts that are affected, e.g. Cmd + C/V work as expected.
Does the dev server intercept shortcuts in some way? Any other ideas what might be causing this?