My point was that you cannot type in a text file unless it is first responder. You're going to have to look into this a bit more carefully.
With macOS apps, there is one pitfall that sometimes trips up developers new to the platform. It's not that difficult to end up creating 2 windows where you meant to have only one. You don't know that you have two, because one is not shown, or because one is exactly on top of the other. In such cases, you get this sort of paradoxical behavior, where an action in the UI can't be "seen" in the code.
I have no particular reason to think you've run into this issue, but you're going to need to poke around with the debugger and/or add debugging code. Just make sure you check your assumptions, when you're trying to figure out what went wrong.