Copy / Paste handled differently in Ableton Live?


#1

I have a WebBrowserComponent running inside a plugin, and in Ableton Live 9 on OS X, cmd key combinations (such as copy / paste) don’t seem to be getting sent correctly to focussed elements within the underlying WebView.

The problem might be related to the fact that in other hosts (e.g. Logic), if a text input field within the WebView has focus and I type cmd-c then the host’s key mapping gets invoked (the host Edit menu becomes highlighted), but in Live this is not the case.

If I set a breakpoint in JuceNSViewClass::keyDown() and type in a text field in the WebView, it works as expected until I type something like cmd-v at which point it hits the breakpoint in keyDown().

The call stack is as follows:

#0	0x000000012758e924 in juce::JuceNSViewClass::keyDown(objc_object*, objc_selector*, NSEvent*) at /Users/../JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:1640
#1	0x00007fffa554bb79 in forwardMethod ()
#2	0x00007fffa554bb79 in forwardMethod ()
#3	0x00007fffafa5bb7a in -[WebFrameView keyDown:] ()
#4	0x00007fffa554bb79 in forwardMethod ()
#5	0x00007fffa554bb79 in forwardMethod ()
#6	0x00007fffa554bb79 in forwardMethod ()
#7	0x00007fffa56e97d6 in -[NSControl keyDown:] ()
#8	0x00007fffafa48835 in -[WebHTMLView keyDown:] ()
#9	0x00007fffa5cc333c in -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] ()
#10	0x00007fffa5cc1f7a in -[NSWindow(NSEventRouting) sendEvent:] ()
#11	0x00007fffa5b47518 in -[NSApplication(NSEvent) sendEvent:] ()

In Logic everything works as normal.

Does JUCE have any kind of separate keyboard input handling for Ableton Live that might be causing this issue?

Jamie


#2

OK, I think I’ve figured out what’s going on here.

Basically, in Live, Copy / Paste and other actions are greyed out / disabled in the Edit menu unless a field that explicitly accepts them currently has focus. These actions are therefore greyed out when TextEditor fields within plugins have focus as well as the previously mentioned WebBrowserComponent HTML fields.

A solution is to manually map the corresponding key events by overriding performKeyEquivalent as follows:

- (BOOL)performKeyEquivalent:(NSEvent *)event {
    if (([event modifierFlags] & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) {
        if ([[event charactersIgnoringModifiers] isEqualToString:@"x"]) {
            return [NSApp sendAction:@selector(cut:) to:[[self window] firstResponder] from:self];
        } else if ([[event charactersIgnoringModifiers] isEqualToString:@"c"]) {
            return [NSApp sendAction:@selector(copy:) to:[[self window] firstResponder] from:self];
        } else if ([[event charactersIgnoringModifiers] isEqualToString:@"v"]) {
            return [NSApp sendAction:@selector(paste:) to:[[self window] firstResponder] from:self];
        } else if ([[event charactersIgnoringModifiers] isEqualToString:@"a"]) {
            return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
        }
    }
    return [super performKeyEquivalent:event];
}

For WebBrowserComponent this can be added to a subclass of WebView and this subclass can be used instead of using WebView in the Pimpl.


#3

Thanks for the code. This is now fixed on develop.