Input method blocked in the presence of modal components

We recently got some feedback from our Japanese users: IMEs do not respond in a text input dialog despite working perfectly fine in our app’s main window. The dialog is basically an AlertWindow with a TextEditor added to desktop after calling enterModalState.

I tried removing enterModalState from the dialog spawning code and was able to regain IME support. I looked into JUCE library code for anything that both has to do with key presses and component modal state and found this line in HWNDComponentPeer::doKeyDown() very fishy.

So this means a key down event gets consumed if any component is made modal, even if the event is on the modal component. I tried removing this condition, shortening this line to return used; and this seems to solve the problem. The question is: are there any side-effects? Did I just fixed a bug or broke a bunch of things as well?

Update

This problem only occurs when running as a VST plugin. It does not affect the standalone version.

I also propose the following fix just to be cautious of breaking anything.

if (auto modalComponent = Component::getCurrentlyModalComponent())
{
    // Consume the event if it's sent to a non-modal ComponentPeer.
    if (modalComponent -> getPeer() != this)
        return true;
}

return used;
1 Like

I have a similar issue described above.
I created an empty plugin project and placed a TextEditor and an editable Label on the UI. If it was loaded as VST3 plugin, they didn’t work, but launching it as standalone both worked and the IME suggestions came up.
I experimented a bit around it and my finding is the following:

bool TextEditor::keyStateChanged (const bool isKeyDown)
{
    if (! isKeyDown)
        return false;

   #if JUCE_WINDOWS
    if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
        return false;  // We need to explicitly allow alt-F4 to pass through on Windows
   #endif

    if ((! consumeEscAndReturnKeys)
         && (KeyPress (KeyPress::escapeKey).isCurrentlyDown()
          || KeyPress (KeyPress::returnKey).isCurrentlyDown()))
        return false;

    // (overridden to avoid forwarding key events to the parent)
    return ! ModifierKeys::currentModifiers.isCommandDown();
}

If I replace the last return with return false then the IME works with TextEditor but not with Label.
I’m not suggesting this is a valid fix at all, but maybe could it be a hint?

2 Likes

Yepp, IME seems half working at this point :slight_smile:

@reuk Do you think guys could look into this in the not-too-far future or should we find a way to be able to use IME in plugins?

I’ve taken a look:

Please try it out and let me know how you get on.

1 Like

As far as I managed to test it, it works very well for me.
Checked in Pro Tools and Reaper+Live11 for VST3.
Thank you!

If any issue comes up later, I’ll let you know.

The patch above introduced a new issue, reported here:

The double-pasting issue should also be fixed on develop now.