Skip to content

Commit 04c1cc1

Browse files
author
Michael Chen
committed
Fix unknown crashes since Xcode comes up to 7.0 and Bump version to 1.4.1.
1 parent dc86764 commit 04c1cc1

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

MCLog/MCLog-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>BNDL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.4.0</string>
20+
<string>1.4.1</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>

MCLog/MCLog.m

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ - (void)addObject:(id)object forKey:(id)key {
8787
NSUInteger keyIndex = [self.keys indexOfObject:key];
8888
if (keyIndex == NSNotFound) {
8989
[self.keys addObject:key];
90-
keyIndex = [self.keys indexOfObject:key];
9190
[self.items addObject:object];
9291
} else {
9392
[self.items replaceObjectAtIndex:keyIndex withObject:object];
@@ -396,6 +395,7 @@ - (void)_clearText
396395

397396
///////////////////////////////////////////////////////////////////////////////////
398397
#pragma mark - MCDVTTextStorage
398+
399399
static IMP OriginalFixAttributesInRangeIMP = nil;
400400

401401
static void *kLastAttributeKey;
@@ -406,14 +406,22 @@ - (void)fixAttributesInRange:(NSRange)range;
406406
@interface NSObject (DVTTextStorage)
407407
- (void)setLastAttribute:(NSDictionary *)attribute;
408408
- (NSDictionary *)lastAttribute;
409+
- (void)setConsoleStorage:(BOOL)consoleStorage;
410+
- (BOOL)consoleStorage;
409411
- (void)updateAttributes:(NSMutableDictionary *)attrs withANSIESCString:(NSString *)ansiEscString;
410412
@end
411413

412414
@implementation MCDVTTextStorage
413415

414416
- (void)fixAttributesInRange:(NSRange)range
415417
{
416-
OriginalFixAttributesInRangeIMP(self, _cmd, range);
418+
// To ignore those text storages which are not for console.
419+
if (!self.consoleStorage) {
420+
return;
421+
}
422+
423+
// Workaround: Comment it out in case of EXC_BAD_ACCESS.
424+
// OriginalFixAttributesInRangeIMP(self, _cmd, range);
417425

418426
__block NSRange lastRange = NSMakeRange(range.location, 0);
419427
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
@@ -463,6 +471,16 @@ - (NSDictionary *)lastAttribute
463471
return objc_getAssociatedObject(self, &kLastAttributeKey);
464472
}
465473

474+
- (void)setConsoleStorage:(BOOL)consoleStorage
475+
{
476+
objc_setAssociatedObject(self, @selector(consoleStorage), @(consoleStorage), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
477+
}
478+
479+
- (BOOL)consoleStorage
480+
{
481+
return [objc_getAssociatedObject(self, @selector(consoleStorage)) boolValue];
482+
}
483+
466484
- (void)updateAttributes:(NSMutableDictionary *)attrs withANSIESCString:(NSString *)ansiEscString
467485
{
468486
NSArray *attrComponents = [ansiEscString componentsSeparatedByString:@";"];
@@ -754,6 +772,11 @@ - (BOOL)addCustomViews
754772
if (!consoleTextView) {
755773
return NO;
756774
}
775+
776+
MCDVTTextStorage *textStorage = [consoleTextView valueForKey:@"textStorage"];
777+
if ([textStorage respondsToSelector:@selector(setConsoleStorage:)]) {
778+
[textStorage setConsoleStorage:YES];
779+
}
757780

758781
contentView = [self getParantViewByClassName:@"DVTControllerContentView" andView:consoleTextView];
759782
NSView *scopeBarView = [self getViewByClassName:@"DVTScopeBarView" andContainerView:contentView];
@@ -895,7 +918,6 @@ void hookIDEConsoleItem()
895918
void hookDVTTextStorage()
896919
{
897920
Class DVTTextStorage = NSClassFromString(@"DVTTextStorage");
898-
899921
Method fixAttributesInRange = class_getInstanceMethod(DVTTextStorage, @selector(fixAttributesInRange:));
900922
OriginalFixAttributesInRangeIMP = method_getImplementation(fixAttributesInRange);
901923
IMP newFixAttributesInRangeIMP = class_getMethodImplementation([MCDVTTextStorage class], @selector(fixAttributesInRange:));

0 commit comments

Comments
 (0)