How to find which NSTextfield is focused

I had a problem finding out who the NSTextfield focuses NSTextfield .

I am creating a multilingual form and have several NSTextfield for data entry. I have to change the text input source for some of the NSTextfields during data entry, and I need this to happen automatically.

I can currently change the input source, as I mentioned here without any problems.

The problem I am facing is to change the original source when the NSTextfield object becomes focused. If I use the delegate method controlTextDidBeginEditing: it changes the original input after entering the first letter. This means that I am losing the first word that I typed in the corresponding language.

Is there any delegate to find him?

+4
source share
2 answers

You can subclass your NSTextField and override - (BOOL)becomeFirstResponder ( NSResponder ) to respond to this kind of event.

Instead, you can try control:textShouldBeginEditing:

0
source

You will need to subclass NSTextField

Swift 3+

 class FocusingTextField : NSTextField { var isFocused : Bool = false override func becomeFirstResponder() -> Bool { let orig = super.becomeFirstResponder() if(orig) { self.isFocused = true } return orig } override func textDidEndEditing(_ notification: Notification) { super.textDidEndEditing(notification) self.isFocused = false } override func selectText(_ sender: Any?) { super.selectText(sender) self.isFocused = true } } 

self.view.window?.firstResponder inside your view controller will be given an NSTextView

0
source

All Articles