Copying as RTF currently isn't tied to a keystroke by default, mainly due to it not being tested very much, but you can do so yourself like so:
- Code: Select all
InputMap im = textArea.getInputMap();
ActionMap am = textArea.getActionMap();
int mods = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | InputEvent.SHIFT_DOWN_MASK;
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_C, mods);
am.put("copyAsRtf", new RSyntaxTextAreaEditorKit.CopyAsRtfAction());
This way you don't have to call copyAsRtf() yourself in something such as a KeyListener. Just add that code wherever you create your RSTA instance.
The above example ties the "Copy as RTF" action to Ctrl+Shift+C (Cmd+Shift+C on Macs) so it doesn't conflict with the standard Ctrl+C copy. There's no reason you couldn't simply override the current copy functionality by removing the "| InputEvent.SHIFT_DOWN_MASK" from the snippet above. Then all of your copying will be in RTF (unless the destination doesn't understand RTF, in which case it'll be plain text like usual).
Let me know how this works out for you!