macOS detect 'Emoji & Symbols' menu item selection

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.

I don't understand the logic of the UI.


You say:

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


- Click somewhere : wherever you click in the view you hide the subject ?

- What happens when you edit the subject (you have to click inside): does the subject field disappear ?


Why not simply let user click either subject field or message field ?

Why hiding the subject field.


I've probably missed something in your design.

This was already implemented like this, not sure why the went with this option (capturing mouse event) instead of something like what you suggest. From a UX point of view I am guessing the goal is to hide the subject field as soon as the user moves away from the subject field (for example when she/he clicks outside the subject field).

Clicking inside the subject field does not hide it (as expected I presume).


In the end I removed all the mouse click capture code and modified:

- (void)controlTextDidEndEditing:(NSNotification *)obj


So that the subject field is hidden there. So far so good.


Thanks for taking the time to review the question.

macOS detect 'Emoji & Symbols' menu item selection
 
 
Q