I’m having problem triggering complete: method for NSTextfield.
for now I can make an distinct array of names from a textfield using @distinctUnionOfObjects ( awesome method to remove duplicates of an array ) and now I can send back autocompletion for this textfield using:
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index
But, this method is not automatic and I have to press ESC button to pop the autocompletion suggestion up for the textfield during data entry.
I searched here and found some examples that make no sense for me.
Short Question:
Is there any method using NSTexfields delegates like controlDidChanged or something like that to do this more easily and clearly ?
I just confuse using complete: method for nstextview.
When your text field delegate gets
controlTextDidChange:, you can callcomplete:on the Field Editor. This is the method that gets called when you press ESC or F5.The tricky part is that when the completion menu is being navigated, it will cause
controlTextDidChange:messages to be sent again, (although without changing the actual string) which will create an infinite loop. You will need some kind of flag to stopcomplete:from being called when you are already in the middle of a completion. For example, you can keep track of the last change the user made to the string and compare it with the current value of the field editor; if there’s no user-initiated change, don’t cause completion: