diff --git a/MCLog/MCLog-Info.plist b/MCLog/MCLog-Info.plist index e9ea73d..11dacdf 100644 --- a/MCLog/MCLog-Info.plist +++ b/MCLog/MCLog-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.4.0 + 1.4.1 CFBundleSignature ???? CFBundleVersion diff --git a/MCLog/MCLog.m b/MCLog/MCLog.m index bd2401f..beb82b4 100644 --- a/MCLog/MCLog.m +++ b/MCLog/MCLog.m @@ -87,7 +87,6 @@ - (void)addObject:(id)object forKey:(id)key { NSUInteger keyIndex = [self.keys indexOfObject:key]; if (keyIndex == NSNotFound) { [self.keys addObject:key]; - keyIndex = [self.keys indexOfObject:key]; [self.items addObject:object]; } else { [self.items replaceObjectAtIndex:keyIndex withObject:object]; @@ -396,6 +395,7 @@ - (void)_clearText /////////////////////////////////////////////////////////////////////////////////// #pragma mark - MCDVTTextStorage + static IMP OriginalFixAttributesInRangeIMP = nil; static void *kLastAttributeKey; @@ -406,6 +406,8 @@ - (void)fixAttributesInRange:(NSRange)range; @interface NSObject (DVTTextStorage) - (void)setLastAttribute:(NSDictionary *)attribute; - (NSDictionary *)lastAttribute; +- (void)setConsoleStorage:(BOOL)consoleStorage; +- (BOOL)consoleStorage; - (void)updateAttributes:(NSMutableDictionary *)attrs withANSIESCString:(NSString *)ansiEscString; @end @@ -413,7 +415,13 @@ @implementation MCDVTTextStorage - (void)fixAttributesInRange:(NSRange)range { - OriginalFixAttributesInRangeIMP(self, _cmd, range); + // To ignore those text storages which are not for console. + if (!self.consoleStorage) { + return; + } + + // Workaround: Comment it out in case of EXC_BAD_ACCESS. + // OriginalFixAttributesInRangeIMP(self, _cmd, range); __block NSRange lastRange = NSMakeRange(range.location, 0); NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; @@ -463,6 +471,16 @@ - (NSDictionary *)lastAttribute return objc_getAssociatedObject(self, &kLastAttributeKey); } +- (void)setConsoleStorage:(BOOL)consoleStorage +{ + objc_setAssociatedObject(self, @selector(consoleStorage), @(consoleStorage), OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (BOOL)consoleStorage +{ + return [objc_getAssociatedObject(self, @selector(consoleStorage)) boolValue]; +} + - (void)updateAttributes:(NSMutableDictionary *)attrs withANSIESCString:(NSString *)ansiEscString { NSArray *attrComponents = [ansiEscString componentsSeparatedByString:@";"]; @@ -754,6 +772,11 @@ - (BOOL)addCustomViews if (!consoleTextView) { return NO; } + + MCDVTTextStorage *textStorage = [consoleTextView valueForKey:@"textStorage"]; + if ([textStorage respondsToSelector:@selector(setConsoleStorage:)]) { + [textStorage setConsoleStorage:YES]; + } contentView = [self getParantViewByClassName:@"DVTControllerContentView" andView:consoleTextView]; NSView *scopeBarView = [self getViewByClassName:@"DVTScopeBarView" andContainerView:contentView]; @@ -895,7 +918,6 @@ void hookIDEConsoleItem() void hookDVTTextStorage() { Class DVTTextStorage = NSClassFromString(@"DVTTextStorage"); - Method fixAttributesInRange = class_getInstanceMethod(DVTTextStorage, @selector(fixAttributesInRange:)); OriginalFixAttributesInRangeIMP = method_getImplementation(fixAttributesInRange); IMP newFixAttributesInRangeIMP = class_getMethodImplementation([MCDVTTextStorage class], @selector(fixAttributesInRange:));