As part of a communication application, I'm working on a chat screen that has a subject for the chat (NSTextField) and a message text input area (NSTextView). The view controller containing both is subscribed to global and local mouse down events like this:
self.globalEventMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask|NSRightMouseDownMask)
handler:^(NSEvent *theEvent) {
[weakSelf onMouseDown:theEvent];
}];
self.localEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:(NSLeftMouseDownMask|NSRightMouseDownMask)
handler:^NSEvent *(NSEvent *theEvent) {
[weakSelf onMouseDown:theEvent];
return theEvent;
}];When the events are generated (user clicks somewhere) the subject field is hidded and the focus is moved to the input text filed (is made first responder). The problem is that when the user is editing the subject field and selects: Edit -> Emoji & Symbols to insert an emoji for example, the subject is hidden, the input text field is set to first responder and the character is inserted in the input text field instead of the subject field.
I tried removing the code that subscribes to local events (so that the subject field is hidden only when the user clicks outside the application) but it didn't work. I guess the Edit -> Emoji & Symbols menu item selection is considered global even when executed from inside the application's Edit menu
QUESTION:
1) How can I detect (if possible) inside the view controller that the user has selected the Emoji & Symbols menu item and avoid the hide & switch first responder action in that case? Or is there a more "macOS appropriate" solution for this case?
PS: I'm new to macOS development.