I want to clear the selection of NSTextView
after it loses focus. How can I achieve that? Thanks in advance!
Kai.
Set up a delegate object (or use your app delegate) that conforms to NSTextDelegate
protocol. Then all you need to do is to implement textDidEndEditing:
to clear the selection. From the docs:
textDidEndEditing:
Informs the delegate that the text object has finished editing (that it has resigned first responder status).
- (void)textDidEndEditing:(NSNotification *)aNotification
Something like:
#ifndef NSZeroRange
#define NSZeroRange NSMakeRange(0,0)
#endif
- (void)textDidEndEditing:(NSNotification *)aNotification {
[myTextView setSelectedRange:NSZeroRange];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With