Skip to content

Commit

Permalink
Fix unknown crashes since Xcode comes up to 7.0 and Bump version to 1…
Browse files Browse the repository at this point in the history
….4.1.
  • Loading branch information
Michael Chen committed Nov 12, 2015
1 parent dc86764 commit 04c1cc1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MCLog/MCLog-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.0</string>
<string>1.4.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
28 changes: 25 additions & 3 deletions MCLog/MCLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -396,6 +395,7 @@ - (void)_clearText

///////////////////////////////////////////////////////////////////////////////////
#pragma mark - MCDVTTextStorage

static IMP OriginalFixAttributesInRangeIMP = nil;

static void *kLastAttributeKey;
Expand All @@ -406,14 +406,22 @@ - (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

@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];
Expand Down Expand Up @@ -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:@";"];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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:));
Expand Down

0 comments on commit 04c1cc1

Please sign in to comment.