From d1fc013f1c596f564d67bdb7530e0762209c3f6d Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 20 Aug 2014 01:42:55 +0200 Subject: [PATCH] Removed duplicate paste commands for autotype --- MacPass/MPAutotypeCommand.m | 10 ++++++++-- MacPass/MPAutotypePaste.h | 1 + MacPass/MPAutotypePaste.m | 7 +++++++ MacPassTests/KPKTestAutotypeNormalization.m | 7 ++----- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 9908c6ef..585156a9 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -151,8 +151,14 @@ + (void)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands { if(pasteContent) { - MPAutotypePaste *pasteCommand = [[MPAutotypePaste alloc] initWithString:pasteContent]; - [commands addObject:pasteCommand]; + /* 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]; + [commands addObject:pasteCommand]; + } } } diff --git a/MacPass/MPAutotypePaste.h b/MacPass/MPAutotypePaste.h index bc85f50d..c36097c1 100644 --- a/MacPass/MPAutotypePaste.h +++ b/MacPass/MPAutotypePaste.h @@ -14,5 +14,6 @@ @interface MPAutotypePaste : MPAutotypeCommand - (instancetype)initWithString:(NSString *)aString; +- (void)appendString:(NSString *)aString; @end \ No newline at end of file diff --git a/MacPass/MPAutotypePaste.m b/MacPass/MPAutotypePaste.m index 66d0b916..ac376b46 100644 --- a/MacPass/MPAutotypePaste.m +++ b/MacPass/MPAutotypePaste.m @@ -27,6 +27,11 @@ return self; } +- (void)appendString:(NSString *)aString { + self.pasteData = [self.pasteData stringByAppendingString:aString]; +} + + - (void)execute { if([self.pasteData length] > 0) { MPPasteBoardController *controller = [MPPasteBoardController defaultController]; @@ -40,4 +45,6 @@ return YES; } + + @end diff --git a/MacPassTests/KPKTestAutotypeNormalization.m b/MacPassTests/KPKTestAutotypeNormalization.m index 3e23a62a..b601694f 100644 --- a/MacPassTests/KPKTestAutotypeNormalization.m +++ b/MacPassTests/KPKTestAutotypeNormalization.m @@ -50,14 +50,11 @@ MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"]; NSArray *commands = [MPAutotypeCommand commandsForContext:context]; - XCTAssert([commands count] == 7); + XCTAssert([commands count] == 4); 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[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}"]; commands = [MPAutotypeCommand commandsForContext:context];