-
Notifications
You must be signed in to change notification settings - Fork 14
/
CustomTextField.m
67 lines (54 loc) · 1.46 KB
/
CustomTextField.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// CustomTextField.m
// SearchField
//
// Created by Patrick Wardle on 8/27/15.
//
//
#import "CustomTextField.h"
#import "AppDelegate.h"
@implementation CustomTextField
@synthesize owner;
@synthesize lastMovement;
//subclass override
// ->see: http://stackoverflow.com/questions/5163646/how-to-make-nssearchfield-send-action-upon-autocompletion/5360535#5360535
-(void)insertCompletion:(NSString *)word forPartialWordRange:(NSRange)charRange movement:(NSInteger)movement isFinal:(BOOL)flag
{
//suppress completion if user types a space
if(movement == NSRightTextMovement)
{
//bail
goto bail;
}
//ignore if 2x 'enter'
if( (movement == NSReturnTextMovement) &&
(self.lastMovement == NSReturnTextMovement) )
{
//bail
goto bail;
}
//update
self.lastMovement = movement;
//show full replacements
if(0 != charRange.location)
{
//update length
charRange.length += charRange.location;
//reset location
charRange.location = 0;
}
//insert completion
// ->will use updated char range!
[super insertCompletion:word forPartialWordRange:charRange movement:movement isFinal:flag];
//on enter
// ->call up into app delegate to process (filter)
if(movement == NSReturnTextMovement)
{
//call up into owner to process
[owner filterAutoComplete:self];
}
//bail
bail:
return;
}
@end