I’m developping an interface with JUCE and I need to be able to control the Copy/Cut/Paste behaviours to do those operations on custom classes in my software. At the same time, I expect the text editors to behave correctly when doing Ctrl+C / Ctrl+V / Ctrl+X .
On Windows, it’s working perfectly, I can select my elements and copy / paste them, and when editing a text, the copy/paste function will only work in the text field.
On OSX, the copy/paste functions are still triggering the code inside my main ApplicationCommandTarget class which is handling the custom copy/paste instead of the text editing ones, resulting in users copy/pasting objects when they expect to just copy/paste the text they’re editing.
If set the command infos to setActive(false), then the copy/pasting work but obviously not my custom functions (also there is a bug in the native mac menu that makes it not refresh when selected, and it needs to be called manually with handleAsyncUpdate(). This is again working just normally on windows and menus get refreshed when clicking on them)
My question is : is is a bug in JUCE, or is it some code that I should place to check that the focus is on a text editor ? As it is just working as expected on Windows and linux, I would imagine that the problem is on the JUCE/OSX side.
I traced back the events to the function menuItemInvoked in juce_mac_MainMenu.mm
it seems to be a native function, which I guess helps understand the difference of behaviour between windows/linux and mac. What seems to happen is that the keypress event is not even passed through the software’s componentPeer stack, but only handled by the ApplicationCommandTarget, so text editors and such can’t catch the event and take priority.
So I would guess that the workaround would be to activate/deactivate the copy/paste menu everytime a text editor is being edited, and force it to update because Mac won’t do it by itself.
Is there a better, cleaner way to do this ? I think to remember that this was not always the case (few years ago I mean)