Skip to content

Commit

Permalink
fix a experience bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lee committed Jan 25, 2016
1 parent 8521afc commit ec566a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
38 changes: 25 additions & 13 deletions MCLog/MCLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ - (void)searchFieldDidEndEditing:(NSNotification *)notification {

NSTextView *consoleTextView = searchField.consoleTextView;
MCLogIDEConsoleArea *consoleArea = searchField.consoleArea;
NSString *cachedKey = hash(consoleArea);
if (cachedKey == nil) {
return;
}

NSString *lastFilterText = nil;
id filterPattern = [self.class filterPatternsMap][cachedKey];
if ([filterPattern isKindOfClass:[NSRegularExpression class]]) {
lastFilterText = ((NSRegularExpression *) filterPattern).pattern;
}
lastFilterText = lastFilterText.length == 0 ? @"" : lastFilterText;

if ([searchField.stringValue isEqualToString:lastFilterText]) {
return;
}

// get rid of the annoying 'undeclared selector' warning
#pragma clang diagnostic push
Expand All @@ -197,19 +212,16 @@ - (void)searchFieldDidEndEditing:(NSNotification *)notification {
[consoleTextView performSelector:@selector(clearConsoleItems) withObject:nil];
}

NSString *cachedKey = hash(consoleArea);
if (cachedKey) {
static SEL selector = nil;
static BOOL canResponse = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
selector = @selector(_appendItems:);
canResponse = [consoleArea respondsToSelector:selector];
});
if (canResponse) {
NSArray *sortedItems = [[self.class consoleItemsMap][cachedKey] orderedItems];
objc_msgSend(consoleArea, selector, sortedItems);
}
static SEL selector = nil;
static BOOL canResponse = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
selector = @selector(_appendItems:);
canResponse = [consoleArea respondsToSelector:selector];
});
if (canResponse) {
NSArray *sortedItems = [[self.class consoleItemsMap][cachedKey] orderedItems];
objc_msgSend(consoleArea, selector, sortedItems);
}
#pragma clang diagnostic pop
}
Expand Down
17 changes: 10 additions & 7 deletions MCLog/MCLogIDEConsoleArea.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ - (BOOL)_shouldAppendItem:(id)obj {
originalIMP = [MethodSwizzleHelper originalIMPForClass:clazz selector:selector];
}


NSSearchField *searchField = getSearchField(self);
if (searchField == nil) {
return YES;
}
if (!searchField.consoleArea) {
searchField.consoleArea = (MCLogIDEConsoleArea *)self;
if (obj == nil) {
return [originalIMP(self, _cmd, obj) boolValue];
}

NSMutableDictionary *consoleItemsMap = [MCLog consoleItemsMap];
Expand Down Expand Up @@ -81,6 +76,14 @@ - (BOOL)_shouldAppendItem:(id)obj {
return NO;
}

NSSearchField *searchField = getSearchField(self);
if (searchField == nil) {
return YES;
}
if (!searchField.consoleArea) {
searchField.consoleArea = (MCLogIDEConsoleArea *)self;
}

if (searchField.stringValue.length == 0) {
[[MCLog filterPatternsMap] removeObjectForKey:consoleItemsKey];
return YES;
Expand Down

0 comments on commit ec566a6

Please sign in to comment.