inlining function

This commit is contained in:
michael starke
2017-01-26 17:28:13 +01:00
parent f0c433cac5
commit 231558d7e8

View File

@@ -23,12 +23,6 @@
static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F5, kVK_F6, kVK_F7, kVK_F8, kVK_F9, kVK_F10, kVK_F11, kVK_F12, kVK_F13, kVK_F14, kVK_F15, kVK_F16, kVK_F17, kVK_F18, kVK_F19 }; static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F5, kVK_F6, kVK_F7, kVK_F8, kVK_F9, kVK_F10, kVK_F11, kVK_F12, kVK_F13, kVK_F14, kVK_F15, kVK_F16, kVK_F17, kVK_F18, kVK_F19 };
typedef struct {
NSUInteger location;
CGEventFlags modifiers;
NSRange commandRange;
} MPAutotypeParserContext;
@interface NSNumber (AutotypeCommand) @interface NSNumber (AutotypeCommand)
@property (nonatomic, readonly, assign) CGEventFlags eventFlagsValue; @property (nonatomic, readonly, assign) CGEventFlags eventFlagsValue;
@@ -139,48 +133,39 @@ typedef struct {
/* add range at the end as terminator */ /* add range at the end as terminator */
[commandRanges addObject:[NSValue valueWithRange:NSMakeRange(context.evaluatedCommand.length, 0)]]; [commandRanges addObject:[NSValue valueWithRange:NSMakeRange(context.evaluatedCommand.length, 0)]];
MPAutotypeParserContext parserCtx; NSUInteger location = 0;
parserCtx.location = 0; CGEventFlags modifiers = 0;
parserCtx.modifiers = 0;
for(NSValue *rangeValue in commandRanges) { for(NSValue *rangeValue in commandRanges) {
NSRange commandRange = rangeValue.rangeValue; NSRange commandRange = rangeValue.rangeValue;
parserCtx.commandRange = commandRange;
[self appendCommandsForContext:context parserContext:&parserCtx toCommands:commands];
}
return commands;
}
+ (void)appendCommandsForContext:(MPAutotypeContext *)context parserContext:(MPAutotypeParserContext *)parserCtx toCommands:(NSMutableArray *)commands {
if(parserCtx == NULL) {
return; // failed!
}
/* All non-commands will get translated into key presses if possible, otherwiese into paste commands */ /* All non-commands will get translated into key presses if possible, otherwiese into paste commands */
if(parserCtx->location < parserCtx->commandRange.location) { if(location < commandRange.location) {
/* If there were modifiers we need to use the next single stroke and update the modifier command */ /* If there were modifiers we need to use the next single stroke and update the modifier command */
if(parserCtx->modifiers) { if(modifiers) {
NSString *modifiedKey = [context.evaluatedCommand substringWithRange:NSMakeRange(parserCtx->location, 1)]; NSString *modifiedKey = [context.evaluatedCommand substringWithRange:NSMakeRange(location, 1)];
MPAutotypeKeyPress *press = [[MPAutotypeKeyPress alloc] initWithModifierMask:parserCtx->modifiers character:modifiedKey]; MPAutotypeKeyPress *press = [[MPAutotypeKeyPress alloc] initWithModifierMask:modifiers character:modifiedKey];
if(press) { if(press) {
[commands addObject:press]; [commands addObject:press];
} }
parserCtx->modifiers = 0; modifiers = 0;
parserCtx->location++; location++;
} }
NSRange textRange = NSMakeRange(parserCtx->location, parserCtx->commandRange.location - parserCtx->location); NSRange textRange = NSMakeRange(location, commandRange.location - location);
if(textRange.length > 0) { if(textRange.length > 0) {
NSString *textValue = [context.evaluatedCommand substringWithRange:textRange]; NSString *textValue = [context.evaluatedCommand substringWithRange:textRange];
[self appendAppropriatePasteCommandForEntry:context.entry withContent:textValue toCommands:commands]; [self appendAppropriatePasteCommandForEntry:context.entry withContent:textValue toCommands:commands];
} }
} }
/* Test for modifer Key */ /* Test for modifer Key */
NSString *commandString = [context.evaluatedCommand substringWithRange:parserCtx->commandRange]; NSString *commandString = [context.evaluatedCommand substringWithRange:commandRange];
/* append commands for non-modifer keys */ /* append commands for non-modifer keys */
if(![self updateModifierMask:&(parserCtx->modifiers) forCommand:commandString]) { if(![self updateModifierMask:&modifiers forCommand:commandString]) {
[self appendCommandForEntry:context.entry withString:commandString toCommands:commands activeModifer:parserCtx->modifiers]; [self appendCommandForEntry:context.entry withString:commandString toCommands:commands activeModifer:modifiers];
parserCtx->modifiers = 0; // Reset the modifers; modifiers = 0; // Reset the modifers;
} }
parserCtx->location = parserCtx->commandRange.location + parserCtx->commandRange.length; location = commandRange.location + commandRange.length;
}
return commands;
} }
+ (void)appendAppropriatePasteCommandForEntry:(KPKEntry *)entry withContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands + (void)appendAppropriatePasteCommandForEntry:(KPKEntry *)entry withContent:(NSString *)pasteContent toCommands:(NSMutableArray *)commands