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.
I don't recommend copying the whole string. It would be fine for your case, but if you're using autocompletion for a large text file, then you'll have all kinds of performance and memory issues. You can just keep track of whether or not you are in the middle of an update. If you have multiple textviews, you could make a dictionary for the isCompleting variables.
- (void) controlTextDidChange: (NSNotification *)note {
NSTextView * fieldEditor = [[note userInfo] objectForKey:@"NSFieldEditor"];
if (!isCompleting) {
isCompleting = YES;
[fieldEditor complete:nil];
isCompleting = NO;
}
}
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