-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathTerminalCopyOnSelect.m
32 lines (28 loc) · 956 Bytes
/
TerminalCopyOnSelect.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
#import <objc/runtime.h>
#import "TerminalCopyOnSelect.h"
#import "TCOSPreferences.h"
@implementation NSObject (TerminalCopyOnSelect)
- (void)
myMouseUp:(NSEvent *)theEvent
{
[self myMouseUp:theEvent];
if(![[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_KEY]) return;
NSString *selectedText = [[(id)self performSelector:@selector(selectedText)] retain];
if([selectedText length] > 0){
[(id)self performSelector:@selector(copy:) withObject:nil];
}
[selectedText release];
}
@end
@implementation TerminalCopyOnSelect
+(void) load
{
// allocate and initialize the preferences which load the user defaults
[TCOSPreferences sharedInstance];
Class class = objc_getClass("TTView");
Method mouseUp = class_getInstanceMethod(class, @selector(mouseUp:));
Method myMouseUp = class_getInstanceMethod(class, @selector(myMouseUp:));
method_exchangeImplementations(mouseUp, myMouseUp);
NSLog(@"TerminalCopyOnSelect installed");
}
@end