Is it possible to add a new keyboard shortcut to draw.io to insert a given element?
In short I want to have a faster way of inserting the General > Text element. Ideally I would like to change the double click event to insert this, instead of a non-linkable text which it uses today.
The reason I can't use the double click, or Ctrl-Shift-X, is that the text element which is inserted then is non-linkable, and can not be connected to to other elements.
Bonus: To add other elements using another shortcut with specified element.
PS! An alternate version could be to use the Ctrl-K, if it was possible to default to a rectangle without line around. 🙂
Best Answer
A plugin to insert elements
It turns out that it is indeed possible to add a plugin, which adds shortcuts to draw.io. Here is plugin code for adding either an ellipse using Ctrl+Shift+Q, or text using Ctrl+Shift+T. For the text node I opted for left justified, and top aligned.
All of this text needs to be added to a file, which is accessible from a given URL. I did this using Google Drive, and fiddled a little to get it to the correct URL to the actual javascript file, which this is.
When you have the link, go to draw.io, and do the following:
Information on plugin code
See "The draw.io plugin system" for the introduction of plugins to draw.io. This is rather scarce, so you need to be experimental and adventerous to make new plugins. You also need to know your way around the developer tools related to your browser to make the full benefit of the following:
Draw.valueOf()
bindAction()
requires the following paramters:!0
, else use!1
!1
, else use!0
Adding an extra menu
The example code of the plugins, linked above, shows how to add menu items, and here is some code to add a menu of your own (add this at the bottom of the
Draw.loadPlugin(function(ui)...
Edit: The complete plugin, insertElementsWithMenu.js, is now available on my newly created github repository: holroy's draw.io plugins. Follow instructions on github to fork out your version, and getting a proper link to the plugin. Here is a permanent link to the initial version of this plugin.