mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 14:02:28 +00:00
String as Autotype command results in only one Paste command - fixed #338
Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -101,15 +101,15 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context {
|
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context {
|
||||||
if(![context isValid]) {
|
if(!context.valid) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
NSUInteger reserverd = MAX(1,[context.normalizedCommand length] / 4);
|
NSUInteger reserverd = MAX(1,context.normalizedCommand.length / 4);
|
||||||
NSMutableArray *commands = [[NSMutableArray alloc] initWithCapacity:reserverd];
|
NSMutableArray *commands = [[NSMutableArray alloc] initWithCapacity:reserverd];
|
||||||
NSMutableArray __block *commandRanges = [[NSMutableArray alloc] initWithCapacity:reserverd];
|
NSMutableArray __block *commandRanges = [[NSMutableArray alloc] initWithCapacity:reserverd];
|
||||||
NSRegularExpression *commandRegExp = [[NSRegularExpression alloc] initWithPattern:@"\\{[^\\{\\}]+\\}" options:NSRegularExpressionCaseInsensitive error:0];
|
NSRegularExpression *commandRegExp = [[NSRegularExpression alloc] initWithPattern:@"\\{[^\\{\\}]+\\}" options:NSRegularExpressionCaseInsensitive error:0];
|
||||||
NSAssert(commandRegExp, @"RegExp is constant. Has to work all the time");
|
NSAssert(commandRegExp, @"RegExp is constant. Has to work all the time");
|
||||||
[commandRegExp enumerateMatchesInString:context.evaluatedCommand options:0 range:NSMakeRange(0, [context.evaluatedCommand length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
|
[commandRegExp enumerateMatchesInString:context.evaluatedCommand options:0 range:NSMakeRange(0, context.evaluatedCommand.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
[commandRanges addObject:[NSValue valueWithRange:result.range]];
|
[commandRanges addObject:[NSValue valueWithRange:result.range]];
|
||||||
}
|
}
|
||||||
@@ -136,32 +136,40 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
|
|||||||
[self appendAppropriatePasteCommandForEntry:context.entry withContent:pasteValue toCommands:commands];
|
[self appendAppropriatePasteCommandForEntry:context.entry withContent:pasteValue toCommands:commands];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Test for modifier Key */
|
/* Test for modifer Key */
|
||||||
NSString *commandString = [context.evaluatedCommand substringWithRange:commandRange];
|
NSString *commandString = [context.evaluatedCommand substringWithRange:commandRange];
|
||||||
/* append commands for non-modifier keys */
|
/* append commands for non-modifer keys */
|
||||||
if(![self updateModifierMask:&collectedModifers forCommand:commandString]) {
|
if(![self updateModifierMask:&collectedModifers forCommand:commandString]) {
|
||||||
[self appendCommandForEntry:context.entry withString:commandString toCommands:commands activeModifer:collectedModifers];
|
[self appendCommandForEntry:context.entry withString:commandString toCommands:commands activeModifer:collectedModifers];
|
||||||
collectedModifers = 0; // Reset the modifiers;
|
collectedModifers = 0; // Reset the modifers;
|
||||||
}
|
}
|
||||||
lastLocation = commandRange.location + commandRange.length;
|
lastLocation = commandRange.location + commandRange.length;
|
||||||
}
|
}
|
||||||
/* Collect any part that isn't a command or if only paste is used */
|
/* Collect last part that isn't a command */
|
||||||
if(lastLocation < [context.evaluatedCommand length]) {
|
if(lastLocation < context.evaluatedCommand.length) {
|
||||||
/* We might have some dangling modifiers */
|
NSRange lastRange = NSMakeRange(lastLocation, context.evaluatedCommand.length - lastLocation);
|
||||||
NSRange lastRange = NSMakeRange(lastLocation, [context.evaluatedCommand length] - lastLocation);
|
if(lastRange.length <= 0) {
|
||||||
if(lastRange.length > 0) {
|
return commands;
|
||||||
|
}
|
||||||
|
/* We have modifiers */
|
||||||
|
if(0 != collectedModifers) {
|
||||||
NSString *modifiedKey = [context.evaluatedCommand substringWithRange:NSMakeRange(lastLocation, 1)];
|
NSString *modifiedKey = [context.evaluatedCommand substringWithRange:NSMakeRange(lastLocation, 1)];
|
||||||
MPAutotypeKeyPress *press = [[MPAutotypeKeyPress alloc] initWithModifierMask:collectedModifers character:modifiedKey];
|
MPAutotypeKeyPress *press = [[MPAutotypeKeyPress alloc] initWithModifierMask:collectedModifers character:modifiedKey];
|
||||||
if(press) {
|
if(press) {
|
||||||
[commands addObject:press];
|
[commands addObject:press];
|
||||||
}
|
}
|
||||||
if(lastRange.length > 1) {
|
/* Update our states */
|
||||||
NSRange pasteRange = NSMakeRange(lastRange.location + 1, lastRange.length - 1);
|
collectedModifers = 0;
|
||||||
|
lastLocation++;
|
||||||
|
lastRange = NSMakeRange(lastLocation, context.evaluatedCommand.length - lastLocation);
|
||||||
|
}
|
||||||
|
/* No modifiers, just paste the rest */
|
||||||
|
if(lastRange.length > 0) {
|
||||||
|
NSRange pasteRange = NSMakeRange(lastRange.location, lastRange.length);
|
||||||
NSString *pasteValue = [context.evaluatedCommand substringWithRange:pasteRange];
|
NSString *pasteValue = [context.evaluatedCommand substringWithRange:pasteRange];
|
||||||
[self appendAppropriatePasteCommandForEntry:context.entry withContent:pasteValue toCommands:commands];
|
[self appendAppropriatePasteCommandForEntry:context.entry withContent:pasteValue toCommands:commands];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +182,7 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (void)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands {
|
+ (void)appendPasteCommandForContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands {
|
||||||
/* Update an already inserted paste command with the new contents */
|
/* Update an already inserted paste command with the new conents */
|
||||||
if([[commands lastObject] isKindOfClass:[MPAutotypePaste class]]) {
|
if([[commands lastObject] isKindOfClass:[MPAutotypePaste class]]) {
|
||||||
[[commands lastObject] appendString:pasteContent];
|
[[commands lastObject] appendString:pasteContent];
|
||||||
}
|
}
|
||||||
@@ -303,7 +311,7 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F
|
|||||||
if([numberScanner scanInteger:&value]) {
|
if([numberScanner scanInteger:&value]) {
|
||||||
if([kKPKAutotypeDelay isEqualToString:uppercaseCommand]) {
|
if([kKPKAutotypeDelay isEqualToString:uppercaseCommand]) {
|
||||||
if(MAX(0, value) <= 0) {
|
if(MAX(0, value) <= 0) {
|
||||||
return; // Value too low, just skip
|
return; // Value too low, just skipp
|
||||||
}
|
}
|
||||||
[commands addObject:[[MPAutotypeDelay alloc] initWithDelay:value]];
|
[commands addObject:[[MPAutotypeDelay alloc] initWithDelay:value]];
|
||||||
return; // Done
|
return; // Done
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
/**
|
/**
|
||||||
* @return YES if valid, NO otherwise
|
* @return YES if valid, NO otherwise
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) BOOL isValid;
|
@property (nonatomic, readonly, assign) BOOL valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Designated initializer
|
* Designated initializer
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)isValid {
|
- (BOOL)valid {
|
||||||
return (self.normalizedCommand != nil);
|
return (self.normalizedCommand != nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,4 +58,13 @@
|
|||||||
return _evaluatedCommand;
|
return _evaluatedCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)description {
|
||||||
|
return [NSString stringWithFormat:@"command:%@\nnormalized:%@\nevaluated:%@\nentry.title:%@\nentry.uuid:%@\n",
|
||||||
|
self.command,
|
||||||
|
self.normalizedCommand,
|
||||||
|
self.evaluatedCommand,
|
||||||
|
self.entry.title,
|
||||||
|
self.entry.uuid.UUIDString];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -78,14 +78,14 @@
|
|||||||
KPKWindowAssociation *association = [entry.autotype windowAssociationMatchingWindowTitle:windowTitle];
|
KPKWindowAssociation *association = [entry.autotype windowAssociationMatchingWindowTitle:windowTitle];
|
||||||
context = [[MPAutotypeContext alloc] initWithWindowAssociation:association];
|
context = [[MPAutotypeContext alloc] initWithWindowAssociation:association];
|
||||||
}
|
}
|
||||||
if(context.isValid) {
|
if(context.valid) {
|
||||||
[contexts addObject:context];
|
[contexts addObject:context];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Fall back to preferred Entry if no match was found */
|
/* Fall back to preferred Entry if no match was found */
|
||||||
if(contexts.count == 0 && usePreferredEntry) {
|
if(contexts.count == 0 && usePreferredEntry) {
|
||||||
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:entry.autotype.defaultKeystrokeSequence];
|
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:entry.autotype.defaultKeystrokeSequence];
|
||||||
if(context.isValid) {
|
if(context.valid) {
|
||||||
[contexts addObject:context];
|
[contexts addObject:context];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user