Removed duplicate paste commands for autotype

This commit is contained in:
michael starke
2014-08-20 01:42:55 +02:00
parent 55d1644b17
commit d1fc013f1c
4 changed files with 18 additions and 7 deletions

View File

@@ -151,10 +151,16 @@
+ (void)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands { + (void)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands {
if(pasteContent) { if(pasteContent) {
/* Update an already inserted paste command with the new conents */
if([[commands lastObject] isKindOfClass:[MPAutotypePaste class]]) {
[[commands lastObject] appendString:pasteContent];
}
else {
MPAutotypePaste *pasteCommand = [[MPAutotypePaste alloc] initWithString:pasteContent]; MPAutotypePaste *pasteCommand = [[MPAutotypePaste alloc] initWithString:pasteContent];
[commands addObject:pasteCommand]; [commands addObject:pasteCommand];
} }
} }
}
+ (void)appendCommandForString:(NSString *)commandString toCommands:(NSMutableArray *)commands activeModifer:(CGEventFlags)flags { + (void)appendCommandForString:(NSString *)commandString toCommands:(NSMutableArray *)commands activeModifer:(CGEventFlags)flags {
if(!commandString) { if(!commandString) {

View File

@@ -14,5 +14,6 @@
@interface MPAutotypePaste : MPAutotypeCommand @interface MPAutotypePaste : MPAutotypeCommand
- (instancetype)initWithString:(NSString *)aString; - (instancetype)initWithString:(NSString *)aString;
- (void)appendString:(NSString *)aString;
@end @end

View File

@@ -27,6 +27,11 @@
return self; return self;
} }
- (void)appendString:(NSString *)aString {
self.pasteData = [self.pasteData stringByAppendingString:aString];
}
- (void)execute { - (void)execute {
if([self.pasteData length] > 0) { if([self.pasteData length] > 0) {
MPPasteBoardController *controller = [MPPasteBoardController defaultController]; MPPasteBoardController *controller = [MPPasteBoardController defaultController];
@@ -40,4 +45,6 @@
return YES; return YES;
} }
@end @end

View File

@@ -50,14 +50,11 @@
MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"]; MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"];
NSArray *commands = [MPAutotypeCommand commandsForContext:context]; NSArray *commands = [MPAutotypeCommand commandsForContext:context];
XCTAssert([commands count] == 7); XCTAssert([commands count] == 4);
XCTAssert([commands[0] isKindOfClass:[MPAutotypePaste class]]); XCTAssert([commands[0] isKindOfClass:[MPAutotypePaste class]]);
XCTAssert([commands[1] isKindOfClass:[MPAutotypePaste class]]); XCTAssert([commands[1] isKindOfClass:[MPAutotypeKeyPress class]]);
XCTAssert([commands[2] isKindOfClass:[MPAutotypePaste class]]); XCTAssert([commands[2] isKindOfClass:[MPAutotypePaste class]]);
XCTAssert([commands[3] isKindOfClass:[MPAutotypeKeyPress class]]); XCTAssert([commands[3] isKindOfClass:[MPAutotypeKeyPress class]]);
XCTAssert([commands[4] isKindOfClass:[MPAutotypePaste class]]);
XCTAssert([commands[5] isKindOfClass:[MPAutotypePaste class]]);
XCTAssert([commands[6] isKindOfClass:[MPAutotypeKeyPress class]]);
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"]; context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"];
commands = [MPAutotypeCommand commandsForContext:context]; commands = [MPAutotypeCommand commandsForContext:context];