Skip to content

Commit b8ee48b

Browse files
committed
Filter when Enter-Key pressed
1 parent b3f0c84 commit b8ee48b

7 files changed

Lines changed: 57 additions & 55 deletions

File tree

LSLog-XCode.xcodeproj/project.pbxproj

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
B15C7B631C197A8300C92958 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B15C7B621C197A8300C92958 /* AppKit.framework */; settings = {ASSET_TAGS = (); }; };
1414
B15C7B651C197A8300C92958 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B15C7B641C197A8300C92958 /* Foundation.framework */; settings = {ASSET_TAGS = (); }; };
1515
B15C7B691C197A8300C92958 /* LSLog-XCode.xcscheme in Resources */ = {isa = PBXBuildFile; fileRef = B15C7B681C197A8300C92958 /* LSLog-XCode.xcscheme */; };
16-
B15C7B6C1C197A8300C92958 /* LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B6B1C197A8300C92958 /* LSLog.m */; };
1716
B15C7B7D1C19873500C92958 /* NSObject+LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B7C1C19873500C92958 /* NSObject+LSLog.m */; settings = {ASSET_TAGS = (); }; };
1817
B15C7B801C19878C00C92958 /* NSTextStorage+LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B7F1C19878C00C92958 /* NSTextStorage+LSLog.m */; settings = {ASSET_TAGS = (); }; };
1918
B15C7B831C1A665C00C92958 /* NSObject+LSSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B821C1A665B00C92958 /* NSObject+LSSwizzle.m */; settings = {ASSET_TAGS = (); }; };
20-
B15C7B891C1A6F7200C92958 /* LSIDEConsoleArea.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B881C1A6F7200C92958 /* LSIDEConsoleArea.m */; settings = {ASSET_TAGS = (); }; };
21-
B15C7B8C1C1A726A00C92958 /* LSIDEConsoleItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B8B1C1A726A00C92958 /* LSIDEConsoleItem.m */; settings = {ASSET_TAGS = (); }; };
19+
B1944C581C27BB4C006071E7 /* LSIDEConsoleArea.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944C531C27BB4C006071E7 /* LSIDEConsoleArea.m */; settings = {ASSET_TAGS = (); }; };
20+
B1944C591C27BB4C006071E7 /* LSIDEConsoleItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944C551C27BB4C006071E7 /* LSIDEConsoleItem.m */; settings = {ASSET_TAGS = (); }; };
21+
B1944C5A1C27BB4C006071E7 /* LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944C571C27BB4C006071E7 /* LSLog.m */; settings = {ASSET_TAGS = (); }; };
2222
/* End PBXBuildFile section */
2323

2424
/* Begin PBXFileReference section */
@@ -31,19 +31,19 @@
3131
B15C7B621C197A8300C92958 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
3232
B15C7B641C197A8300C92958 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
3333
B15C7B681C197A8300C92958 /* LSLog-XCode.xcscheme */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "LSLog-XCode.xcscheme"; path = "LSLog-XCode.xcodeproj/xcshareddata/xcschemes/LSLog-XCode.xcscheme"; sourceTree = SOURCE_ROOT; };
34-
B15C7B6A1C197A8300C92958 /* LSLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LSLog.h; sourceTree = "<group>"; };
35-
B15C7B6B1C197A8300C92958 /* LSLog.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LSLog.m; sourceTree = "<group>"; };
3634
B15C7B701C197A8300C92958 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3735
B15C7B7B1C19873500C92958 /* NSObject+LSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+LSLog.h"; sourceTree = "<group>"; };
3836
B15C7B7C1C19873500C92958 /* NSObject+LSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+LSLog.m"; sourceTree = "<group>"; };
3937
B15C7B7E1C19878C00C92958 /* NSTextStorage+LSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTextStorage+LSLog.h"; sourceTree = "<group>"; };
4038
B15C7B7F1C19878C00C92958 /* NSTextStorage+LSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTextStorage+LSLog.m"; sourceTree = "<group>"; };
4139
B15C7B811C1A665B00C92958 /* NSObject+LSSwizzle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+LSSwizzle.h"; sourceTree = "<group>"; };
4240
B15C7B821C1A665B00C92958 /* NSObject+LSSwizzle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+LSSwizzle.m"; sourceTree = "<group>"; };
43-
B15C7B871C1A6F7200C92958 /* LSIDEConsoleArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleArea.h; sourceTree = "<group>"; };
44-
B15C7B881C1A6F7200C92958 /* LSIDEConsoleArea.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleArea.m; sourceTree = "<group>"; };
45-
B15C7B8A1C1A726A00C92958 /* LSIDEConsoleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleItem.h; sourceTree = "<group>"; };
46-
B15C7B8B1C1A726A00C92958 /* LSIDEConsoleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleItem.m; sourceTree = "<group>"; };
41+
B1944C521C27BB4C006071E7 /* LSIDEConsoleArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleArea.h; sourceTree = "<group>"; };
42+
B1944C531C27BB4C006071E7 /* LSIDEConsoleArea.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleArea.m; sourceTree = "<group>"; };
43+
B1944C541C27BB4C006071E7 /* LSIDEConsoleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleItem.h; sourceTree = "<group>"; };
44+
B1944C551C27BB4C006071E7 /* LSIDEConsoleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleItem.m; sourceTree = "<group>"; };
45+
B1944C561C27BB4C006071E7 /* LSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSLog.h; sourceTree = "<group>"; };
46+
B1944C571C27BB4C006071E7 /* LSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSLog.m; sourceTree = "<group>"; };
4747
/* End PBXFileReference section */
4848

4949
/* Begin PBXFrameworksBuildPhase section */
@@ -102,12 +102,7 @@
102102
children = (
103103
B136427F1C1AC81F00D82640 /* Settings */,
104104
B15C7B7A1C19873500C92958 /* Category */,
105-
B15C7B6A1C197A8300C92958 /* LSLog.h */,
106-
B15C7B6B1C197A8300C92958 /* LSLog.m */,
107-
B15C7B871C1A6F7200C92958 /* LSIDEConsoleArea.h */,
108-
B15C7B881C1A6F7200C92958 /* LSIDEConsoleArea.m */,
109-
B15C7B8A1C1A726A00C92958 /* LSIDEConsoleItem.h */,
110-
B15C7B8B1C1A726A00C92958 /* LSIDEConsoleItem.m */,
105+
B1944C511C27BB4C006071E7 /* LSLog */,
111106
B15C7B671C197A8300C92958 /* Supporting Files */,
112107
);
113108
path = "LSLog-XCode";
@@ -135,6 +130,19 @@
135130
path = Category;
136131
sourceTree = "<group>";
137132
};
133+
B1944C511C27BB4C006071E7 /* LSLog */ = {
134+
isa = PBXGroup;
135+
children = (
136+
B1944C521C27BB4C006071E7 /* LSIDEConsoleArea.h */,
137+
B1944C531C27BB4C006071E7 /* LSIDEConsoleArea.m */,
138+
B1944C541C27BB4C006071E7 /* LSIDEConsoleItem.h */,
139+
B1944C551C27BB4C006071E7 /* LSIDEConsoleItem.m */,
140+
B1944C561C27BB4C006071E7 /* LSLog.h */,
141+
B1944C571C27BB4C006071E7 /* LSLog.m */,
142+
);
143+
path = LSLog;
144+
sourceTree = "<group>";
145+
};
138146
/* End PBXGroup section */
139147

140148
/* Begin PBXNativeTarget section */
@@ -203,10 +211,10 @@
203211
isa = PBXSourcesBuildPhase;
204212
buildActionMask = 2147483647;
205213
files = (
206-
B15C7B8C1C1A726A00C92958 /* LSIDEConsoleItem.m in Sources */,
207-
B15C7B891C1A6F7200C92958 /* LSIDEConsoleArea.m in Sources */,
214+
B1944C591C27BB4C006071E7 /* LSIDEConsoleItem.m in Sources */,
215+
B1944C581C27BB4C006071E7 /* LSIDEConsoleArea.m in Sources */,
208216
B15C7B7D1C19873500C92958 /* NSObject+LSLog.m in Sources */,
209-
B15C7B6C1C197A8300C92958 /* LSLog.m in Sources */,
217+
B1944C5A1C27BB4C006071E7 /* LSLog.m in Sources */,
210218
B13642821C1AC83700D82640 /* LSLogSettings.m in Sources */,
211219
B136428B1C1D83E600D82640 /* LSLogSettingsWindowController.m in Sources */,
212220
B15C7B801C19878C00C92958 /* NSTextStorage+LSLog.m in Sources */,
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ - (BOOL)_shouldAppendItem:(id)obj {
3030
[cachedItems setObject:obj forKey:@([obj timestamp])];
3131
}
3232

33-
NSInteger filterMode = [[self valueForKey:@"filterMode"] intValue];
34-
BOOL shouldShowLogLevel = YES;
3533
BOOL isForcedShow = [[obj valueForKey:@"input"] boolValue]
36-
|| [[obj valueForKey:@"prompt"] boolValue]
37-
|| [[obj valueForKey:@"outputRequestedByUser"] boolValue]
38-
|| [[obj valueForKey:@"adaptorType"] hasSuffix:@".Debugger"];
34+
|| [[obj valueForKey:@"prompt"] boolValue]
35+
|| [[obj valueForKey:@"outputRequestedByUser"] boolValue]
36+
|| [[obj valueForKey:@"adaptorType"] hasSuffix:@".Debugger"];
37+
if (isForcedShow) {
38+
return YES;
39+
}
40+
41+
NSInteger filterMode = [[self valueForKey:@"filterMode"] intValue];
42+
BOOL shouldShowLogLevel = NO;
3943
if (filterMode >= LSLogLevelVerbose) {
40-
shouldShowLogLevel = [obj logLevel] >= filterMode || isForcedShow;
44+
shouldShowLogLevel = [obj logLevel] >= filterMode;
4145
} else {
42-
shouldShowLogLevel = [LSLog.originalShouldAppendItemIMP(self, _cmd, obj) boolValue];
46+
shouldShowLogLevel = [[LSLog originalShouldAppendItemIMP](self, _cmd, obj) boolValue];
4347
}
4448

4549
if (!shouldShowLogLevel) {
@@ -54,19 +58,19 @@ - (BOOL)_shouldAppendItem:(id)obj {
5458
// Match with regex
5559
NSError *error;
5660
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:filterString
57-
options:(NSRegularExpressionCaseInsensitive|NSRegularExpressionDotMatchesLineSeparators)
58-
error:&error];
61+
options:(NSRegularExpressionCaseInsensitive|NSRegularExpressionDotMatchesLineSeparators)
62+
error:&error];
5963
NSString *content = [obj content];
6064
NSArray *matches = [regex matchesInString:content options:0 range:NSMakeRange(0, content.length)];
61-
if ([matches count] > 0 || isForcedShow) {
65+
if ([matches count] > 0) {
6266
return YES;
6367
}
6468

6569
return NO;
6670
}
6771

6872
- (void)_clearText {
69-
LSLog.originalClearTextIMP(self, _cmd);
73+
[LSLog originalClearTextIMP](self, _cmd);
7074
[[LSLog originalConsoleAreaItemsDict] removeObjectForKey:[self ls_hash]];
7175
}
7276

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
#import "LSIDEConsoleItem.h"
1010
#import "LSLog.h"
11-
#import "LSLogSettings.h"
1211
#import "NSObject+LSLog.h"
1312

1413
@implementation LSIDEConsoleItem
1514

1615
- (id)initWithAdaptorType:(id)arg1 content:(id)arg2 kind:(int)arg3 {
17-
id item = LSLog.originalConsoleItemInitIMP(self, _cmd, arg1, arg2, arg3);
16+
id item = [LSLog originalConsoleItemInitIMP](self, _cmd, arg1, arg2, arg3);
1817
if (![LSLog hasXcodeColorsInstalled]) {
1918
[self ls_updateItemAttribute:item];
2019
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ extern NSMutableArray *originalConsoleItems;
4747
+ (instancetype)sharedPlugin;
4848

4949
/**
50-
* NSMutableDictionary<Obj : NSMutableDictionary<@timestamp, item>>
50+
* NSMutableDictionary<Obj : NSMutableDictionary<@timestamp, IDEConsoleItem>>
5151
*
5252
* @return Cached console items
5353
*/
5454
+ (NSMutableDictionary *)originalConsoleAreaItemsDict;
55+
+ (BOOL)hasXcodeColorsInstalled;
5556
+ (IMP)originalShouldAppendItemIMP;
5657
+ (IMP)originalClearTextIMP;
5758
+ (IMP)originalConsoleItemInitIMP;
58-
+ (BOOL)hasXcodeColorsInstalled;
5959

6060
@end
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
static BOOL _hasXcodeColorsInstalled = NO;
2626

2727

28-
@interface LSLog() <NSSearchFieldDelegate>
28+
@interface LSLog()
2929

3030
@property (nonatomic, strong, readwrite) LSLogSettingsWindowController *settingsPanel;
3131

@@ -111,12 +111,14 @@ - (void)onIDEControlGroupDidChange:(NSNotification*)notification {
111111
});
112112
}
113113

114-
- (void)onFilterFieldDidChange:(NSNotification*)notification {
115-
if (![[notification object] isMemberOfClass:[NSSearchField class]]) {
116-
return;
117-
}
118-
119-
NSSearchField *searchField = [notification object];
114+
#pragma mark - Action
115+
116+
- (void)onSettingsButtonClicked:(NSButton *)sender {
117+
self.settingsPanel = [[LSLogSettingsWindowController alloc] initWithWindowNibName:@"LSLogSettingsWindowController"];
118+
[self.settingsPanel showWindow:self.settingsPanel];
119+
}
120+
121+
- (void)onFilterFieldDidEnter:(NSSearchField *)searchField {
120122
if (![searchField respondsToSelector:@selector(consoleTextView)]) {
121123
return;
122124
}
@@ -135,26 +137,15 @@ - (void)onFilterFieldDidChange:(NSNotification*)notification {
135137
}
136138

137139
if ([consoleArea respondsToSelector:@selector(_appendItems:)]) {
138-
139140
NSMutableDictionary *cacheItems = [[LSLog originalConsoleAreaItemsDict] objectForKey:[consoleArea ls_hash]];
140141
NSArray *sortedKeys = [[cacheItems allKeys] sortedArrayUsingSelector:@selector(compare:)];
141-
NSMutableArray *sortedItems = [NSMutableArray array];
142-
for (NSNumber *key in sortedKeys) {
143-
[sortedItems addObject:cacheItems[key]];
144-
}
142+
NSArray *sortedItems = [cacheItems objectsForKeys:sortedKeys notFoundMarker:[NSClassFromString(@"IDEConsoleItem") new]];
145143

146144
[consoleArea performSelector:@selector(_appendItems:) withObject:sortedItems];
147145
}
148146
#pragma clang diagnostic pop
149147
}
150148

151-
#pragma mark - Action
152-
153-
- (void)onSettingsButtonClicked:(NSButton *)sender {
154-
self.settingsPanel = [[LSLogSettingsWindowController alloc] initWithWindowNibName:@"LSLogSettingsWindowController"];
155-
[self.settingsPanel showWindow:self.settingsPanel];
156-
}
157-
158149
#pragma mark - Private
159150

160151
- (void)addFilterViews {
@@ -236,12 +227,12 @@ - (void)addFilterViews {
236227
filterField.tag = LSLogViewTagFilterField;
237228
filterField.autoresizingMask = NSViewMinXMargin | NSViewMinYMargin;
238229
filterField.font = [NSFont systemFontOfSize:11.0];
239-
filterField.delegate = self;
230+
filterField.sendsWholeSearchString = YES;
231+
[filterField setTarget:self];
232+
[filterField setAction:@selector(onFilterFieldDidEnter:)];
240233
filterField.consoleTextView = (NSTextView *)consoleTextView;
241234
[filterField.cell setPlaceholderString:@"Regular Expression"];
242235
[scopeBarView addSubview:filterField];
243-
244-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFilterFieldDidChange:) name:NSControlTextDidChangeNotification object:nil];
245236
}
246237

247238
- (NSView *)getViewByClassName:(NSString *)className inContainerView:(NSView *)container {

0 commit comments

Comments
 (0)