From 74407ee1824ed47206d3d7c750278fde86053e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Tue, 17 Feb 2015 00:32:21 +0100 Subject: [PATCH 01/20] Hide completion list and inline preview on no completions. Issue #55 TODO: Handle reappearing completions use-case. In case all completions are hidden due to filters we do not hide the list as they might reappear. --- .../DVTTextCompletionSession+FuzzyAutocomplete.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m index faa721e..9ef5d98 100644 --- a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m @@ -409,6 +409,16 @@ - (void)_fa_setFilteringPrefix: (NSString *) prefix forceFilter: (BOOL) forceFil self.fa_filteringTime = [NSDate timeIntervalSinceReferenceDate] - start; + if (![self _gotUsefulCompletionsToShowInList: results.allItems]) { + BOOL shownExplicitly = [[self valueForKey:@"_shownExplicitly"] boolValue]; + if ([self.listWindowController showingWindow] && !shownExplicitly) { + [self.listWindowController hideWindowWithReason: 8]; + } + if ([self._inlinePreviewController isShowingInlinePreview]) { + [self._inlinePreviewController hideInlinePreviewWithReason: 8]; + } + } + NAMED_TIMER_START(SendNotifications); // send the notifications in the same way the original does [self willChangeValueForKey:@"filteredCompletionsAlpha"]; From 14642e16a3449a4b44f0ab940549820053f36a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20=C5=9Ala=C5=BCy=C5=84ski?= Date: Thu, 19 Feb 2015 20:21:55 -0800 Subject: [PATCH 02/20] Do not show autocompletions for strings starting with numbers. Issue #58 --- .../DVTTextCompletionSession+FuzzyAutocomplete.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m index 9ef5d98..24f6a49 100644 --- a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m @@ -418,7 +418,7 @@ - (void)_fa_setFilteringPrefix: (NSString *) prefix forceFilter: (BOOL) forceFil [self._inlinePreviewController hideInlinePreviewWithReason: 8]; } } - + NAMED_TIMER_START(SendNotifications); // send the notifications in the same way the original does [self willChangeValueForKey:@"filteredCompletionsAlpha"]; @@ -435,6 +435,14 @@ - (void)_fa_setFilteringPrefix: (NSString *) prefix forceFilter: (BOOL) forceFil [self didChangeValueForKey:@"selectedCompletionIndex"]; NAMED_TIMER_STOP(SendNotifications); + if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember: [prefix characterAtIndex:0]]) { + BOOL shownExplicitly = [[self valueForKey:@"_shownExplicitly"] boolValue]; + if (!shownExplicitly) { + [self._inlinePreviewController hideInlinePreviewWithReason: 2]; + [self.listWindowController hideWindowWithReason: 2]; + } + } + if (![FASettings currentSettings].showInlinePreview) { [self._inlinePreviewController hideInlinePreviewWithReason: 0x0]; } From 299be3e2ae47e54404be366b29e787a322c42b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20=C5=9Ala=C5=BCy=C5=84ski?= Date: Thu, 19 Feb 2015 22:24:57 -0800 Subject: [PATCH 03/20] Make completions disappear also if there still are hidden ones. It turns out it will reappear just fine. Issue #55 --- FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m index 24f6a49..ac18e21 100644 --- a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m @@ -409,7 +409,7 @@ - (void)_fa_setFilteringPrefix: (NSString *) prefix forceFilter: (BOOL) forceFil self.fa_filteringTime = [NSDate timeIntervalSinceReferenceDate] - start; - if (![self _gotUsefulCompletionsToShowInList: results.allItems]) { + if (![self _gotUsefulCompletionsToShowInList: results.filteredItems]) { BOOL shownExplicitly = [[self valueForKey:@"_shownExplicitly"] boolValue]; if ([self.listWindowController showingWindow] && !shownExplicitly) { [self.listWindowController hideWindowWithReason: 8]; From b618600013df11a799ab7b6909af3d179316994f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Wed, 6 May 2015 21:48:54 +0200 Subject: [PATCH 04/20] Handle tokens of `<#foo##bar#>` when stripping for inline preview ... they seem to appear in Swift completions quite often --- ...nlinePreviewController+FuzzyAutocomplete.m | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/FuzzyAutocomplete/DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m index 0d13ea0..5143194 100644 --- a/FuzzyAutocomplete/DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m @@ -145,9 +145,39 @@ @implementation FAPreviewItem { + (instancetype)previewItemForItem:(id)item { FAPreviewItem * ret = [FAPreviewItem new]; ret->_item = item; + NSString * completionText = item.completionText; - completionText = [completionText stringByReplacingOccurrencesOfString:@"<#" withString:@""]; - completionText = [completionText stringByReplacingOccurrencesOfString:@"#>" withString:@""]; + NSUInteger length = completionText.length; + + NSRange searchRange = NSMakeRange(0, length); + NSUInteger closeToken, middleToken, openToken = [completionText rangeOfString: @"<#" options: 0 range: searchRange].location; + + if (openToken != NSNotFound) { + NSMutableString * newCompletionText = [NSMutableString stringWithCapacity: length]; + while (openToken != NSNotFound) { + searchRange.length = openToken - searchRange.location; + [newCompletionText appendString: [completionText substringWithRange: searchRange]]; + searchRange.location = openToken + 2; + searchRange.length = length - openToken - 2; + closeToken = [completionText rangeOfString: @"#>" options: 0 range: searchRange].location; + if (closeToken != NSNotFound) { + searchRange.length = closeToken - openToken - 2; + middleToken = [completionText rangeOfString: @"##" options: 0 range: searchRange].location; + if (middleToken != NSNotFound) { + searchRange.length = middleToken - openToken - 2; + } + [newCompletionText appendString: [completionText substringWithRange: searchRange]]; + searchRange.location = closeToken + 2; + searchRange.length = length - closeToken - 2; + } + openToken = [completionText rangeOfString: @"<#" options: 0 range: searchRange].location; + } + if (searchRange.location < length) { + [newCompletionText appendString: [completionText substringWithRange: searchRange]]; + } + completionText = newCompletionText; + } + ret->_completionText = completionText; return ret; } From 760b530da180acf62d908aab1c4ddad003c651c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Wed, 6 May 2015 21:53:40 +0200 Subject: [PATCH 05/20] Try not to match type and internal parameter names in Swift completions `completionText` stripped of tokens seems to be a good approximation for this --- ...TTextCompletionSession+FuzzyAutocomplete.m | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m index ac18e21..3bc53b2 100644 --- a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m @@ -40,6 +40,10 @@ @implementation FAFilteringResults @end +static NSString * _fa_IDESwiftCompletionItem_name(id self, SEL _cmd); + +static IMP __fa_IDESwiftCompletionItem_name = (IMP) _fa_IDESwiftCompletionItem_name; + @implementation DVTTextCompletionSession (FuzzyAutocomplete) + (void) fa_swizzleMethods { @@ -78,6 +82,13 @@ + (void) fa_swizzleMethods { [self jr_swizzleMethod: @selector(hideCompletionsWithReason:) withMethod: @selector(_fa_hideCompletionsWithReason:) error: nil]; + + Class swiftCompletionClass = NSClassFromString(@"IDESwiftCompletionItem"); + if (swiftCompletionClass) { + Method m = class_getInstanceMethod(swiftCompletionClass, NSSelectorFromString(@"name")); + __fa_IDESwiftCompletionItem_name = method_setImplementation(m, __fa_IDESwiftCompletionItem_name); + } + } #pragma mark - public methods @@ -980,3 +991,40 @@ - (FAFilteringResults *) _fa_lastFilteringResults { } @end + +static NSString * _fa_IDESwiftCompletionItem_name(id self, SEL _cmd) { + NSString * name = objc_getAssociatedObject(self, _fa_IDESwiftCompletionItem_name); + if (name) { + return name; + } + + id item = self; + name = [item completionText]; + NSUInteger length = name.length; + + NSRange searchRange = NSMakeRange(0, length); + NSUInteger tokenLocation = [name rangeOfString: @"<#" options: 0 range: searchRange].location; + + if (tokenLocation != NSNotFound) { + NSMutableString * newName = [NSMutableString stringWithCapacity: length]; + while (tokenLocation != NSNotFound) { + searchRange.length = tokenLocation - searchRange.location; + [newName appendString: [name substringWithRange: searchRange]]; + searchRange.location = tokenLocation + 2; + searchRange.length = length - tokenLocation - 2; + tokenLocation = [name rangeOfString: @"#>" options: 0 range: searchRange].location; + if (tokenLocation != NSNotFound) { + searchRange.location = tokenLocation + 2; + searchRange.length = length - tokenLocation - 2; + tokenLocation = [name rangeOfString: @"<#" options: 0 range: searchRange].location; + } + } + if (searchRange.location < length) { + [newName appendString: [name substringWithRange: searchRange]]; + } + name = newName; + } + + objc_setAssociatedObject(self, _fa_IDESwiftCompletionItem_name, name, OBJC_ASSOCIATION_RETAIN); + return name; +} From 97f47cdb3effd77557da0df6348371485e463e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Tue, 9 Jun 2015 00:14:16 +0200 Subject: [PATCH 06/20] Add support for Xcode 7 Beta - add the UUID - switch between {IDe,DVT}OpenQuicklyPattern at runtime --- FuzzyAutocomplete.xcodeproj/project.pbxproj | 8 +++- FuzzyAutocomplete/FAMatchPattern.h | 4 +- FuzzyAutocomplete/FAOpenQuicklyPattern.h | 29 +++++++++++++ FuzzyAutocomplete/FAOpenQuicklyPattern.m | 42 +++++++++++++++++++ .../FuzzyAutocomplete-Info.plist | 1 + FuzzyAutocomplete/FuzzyAutocomplete.m | 17 ++++++++ XcodeHeaders/IDEOpenQuicklyPattern.h | 35 ---------------- 7 files changed, 97 insertions(+), 39 deletions(-) create mode 100644 FuzzyAutocomplete/FAOpenQuicklyPattern.h create mode 100644 FuzzyAutocomplete/FAOpenQuicklyPattern.m delete mode 100644 XcodeHeaders/IDEOpenQuicklyPattern.h diff --git a/FuzzyAutocomplete.xcodeproj/project.pbxproj b/FuzzyAutocomplete.xcodeproj/project.pbxproj index 47bed26..839494c 100644 --- a/FuzzyAutocomplete.xcodeproj/project.pbxproj +++ b/FuzzyAutocomplete.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1C56EBE11B2646310001979E /* FAOpenQuicklyPattern.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C56EBE01B2646310001979E /* FAOpenQuicklyPattern.m */; }; 580BC1EC181243D600D53F1F /* DVTFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 580BC1EA181243D600D53F1F /* DVTFoundation.framework */; }; 580BC1ED181243D600D53F1F /* DVTKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 580BC1EB181243D600D53F1F /* DVTKit.framework */; }; 58501C0618165B0600AA3179 /* JRSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 58501C0518165B0600AA3179 /* JRSwizzle.m */; }; @@ -28,6 +29,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1C56EBE01B2646310001979E /* FAOpenQuicklyPattern.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FAOpenQuicklyPattern.m; sourceTree = ""; }; 1C5CF4601918DB6200AF581C /* NSArray+FirstObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+FirstObject.h"; sourceTree = ""; }; 580BC1EA181243D600D53F1F /* DVTFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTFoundation.framework; path = ../../../../Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework; sourceTree = ""; }; 580BC1EB181243D600D53F1F /* DVTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTKit.framework; path = ../../../../Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework; sourceTree = ""; }; @@ -51,7 +53,7 @@ 58DA96F21813D38A00D0082B /* DVTTextCompletionInlinePreviewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTTextCompletionInlinePreviewController.h; sourceTree = ""; }; 58DA96F31813D48D00D0082B /* DVTTextCompletionItem-Protocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DVTTextCompletionItem-Protocol.h"; sourceTree = ""; }; 58E391E7181289A100C18DBF /* IDEIndexCompletionItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEIndexCompletionItem.h; sourceTree = ""; }; - 58E9F98D18139EC5000928AF /* IDEOpenQuicklyPattern.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEOpenQuicklyPattern.h; sourceTree = ""; }; + 58E9F98D18139EC5000928AF /* FAOpenQuicklyPattern.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FAOpenQuicklyPattern.h; sourceTree = ""; }; 58E9F98E1813A0FE000928AF /* IDEKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IDEKit.framework; path = ../../../../Applications/Xcode.app/Contents/Frameworks/IDEKit.framework; sourceTree = ""; }; 6503E741190AB08D00017267 /* DVTTextStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTTextStorage.h; sourceTree = ""; }; 6503E742190AB08D00017267 /* DVTTextStorageDelegate-Protocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DVTTextStorageDelegate-Protocol.h"; sourceTree = ""; }; @@ -112,7 +114,6 @@ 65E3D500190AAD8400A42F56 /* DVTCompletingTextView.h */, 58BA07BF18124BD50070060D /* DVTTextCompletionSession.h */, 58E391E7181289A100C18DBF /* IDEIndexCompletionItem.h */, - 58E9F98D18139EC5000928AF /* IDEOpenQuicklyPattern.h */, 658A7C8218A13279007655E0 /* DVTPreferenceSet-Protocol.h */, 65DB740C18A12FBF001CDD83 /* DVTFontAndColorTheme.h */, ); @@ -182,6 +183,8 @@ 65599234189FFFD600C44208 /* DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m */, 655738C618F47F1E003FD40A /* FATextCompletionListHeaderView.h */, 655738C718F47F1E003FD40A /* FATextCompletionListHeaderView.m */, + 58E9F98D18139EC5000928AF /* FAOpenQuicklyPattern.h */, + 1C56EBE01B2646310001979E /* FAOpenQuicklyPattern.m */, 650C2FA4190B31600021BCD8 /* FAMatchPattern.h */, 650C2FA5190B31600021BCD8 /* FAMatchPattern.m */, ); @@ -299,6 +302,7 @@ 6540232C18F9F79700D580B3 /* FAItemScoringMethod.m in Sources */, 58501C0618165B0600AA3179 /* JRSwizzle.m in Sources */, 58C3C25A181128140031D9CD /* FuzzyAutocomplete.m in Sources */, + 1C56EBE11B2646310001979E /* FAOpenQuicklyPattern.m in Sources */, 650C2FA6190B31600021BCD8 /* FAMatchPattern.m in Sources */, 650D4F5F18E5FCFF00F5DBEE /* FASettings.m in Sources */, 65EAE5DE18ECADF900F0974C /* FATheme.m in Sources */, diff --git a/FuzzyAutocomplete/FAMatchPattern.h b/FuzzyAutocomplete/FAMatchPattern.h index 77e564c..f48c761 100644 --- a/FuzzyAutocomplete/FAMatchPattern.h +++ b/FuzzyAutocomplete/FAMatchPattern.h @@ -6,10 +6,10 @@ // // -#import "IDEOpenQuicklyPattern.h" +#import "FAOpenQuicklyPattern.h" /// Fuzzy Autocomplete Match Pattern -@interface FAMatchPattern : IDEOpenQuicklyPattern +@interface FAMatchPattern : FAOpenQuicklyPattern - (instancetype) initWithPattern: (NSString *) patternString; diff --git a/FuzzyAutocomplete/FAOpenQuicklyPattern.h b/FuzzyAutocomplete/FAOpenQuicklyPattern.h new file mode 100644 index 0000000..0d45c52 --- /dev/null +++ b/FuzzyAutocomplete/FAOpenQuicklyPattern.h @@ -0,0 +1,29 @@ +// +// FAOpenQuicklyPattern.h +// FuzzyAutocomplete +// +// Created by Leszek Ślażyński on 08/06/15. +// +// + +/// Dummy class to be switched to real open quickly pattern on runtime +@interface FAOpenQuicklyPattern : NSObject { + NSString *_pattern; + BOOL _patternHasSeparators; + char *_charactersInPattern; + unsigned short *_patternCharacters; + unsigned short *_lowerCasePatternCharacters; + NSUInteger _patternLength; +} + +@property(readonly) NSString * pattern; + +- (instancetype) initWithPattern: (NSString *) patternString; ++ (instancetype) patternWithInput: (NSString *) input; +- (CGFloat) scoreCandidate: (NSString *) candidate matchedRanges: (NSArray **) rangesPtr; +- (NSArray *) matchedRanges: (NSString *) candidate; +- (CGFloat) scoreCandidate: (NSString *) candidate; +- (BOOL) matchesCandidate: (NSString *) candidate; + +@end + diff --git a/FuzzyAutocomplete/FAOpenQuicklyPattern.m b/FuzzyAutocomplete/FAOpenQuicklyPattern.m new file mode 100644 index 0000000..be0917f --- /dev/null +++ b/FuzzyAutocomplete/FAOpenQuicklyPattern.m @@ -0,0 +1,42 @@ +// +// FAOpenQuicklyPattern.m +// FuzzyAutocomplete +// +// Created by Leszek Ślażyński on 08/06/15. +// +// + +#import "FAOpenQuicklyPattern.h" + +@implementation FAOpenQuicklyPattern + +- (NSString *) pattern { + return nil; +} + +- (instancetype) initWithPattern: (NSString *) patternString { + return nil; +} + ++ (instancetype) patternWithInput: (NSString *) input { + return nil; +} + +- (CGFloat) scoreCandidate: (NSString *) candidate matchedRanges: (NSArray **) rangesPtr { + return 0; +} + +- (NSArray *) matchedRanges: (NSString *) candidate { + return nil; +} + +- (CGFloat) scoreCandidate: (NSString *) candidate { + return 0; +} + + +- (BOOL) matchesCandidate: (NSString *) candidate { + return NO; +} + +@end \ No newline at end of file diff --git a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist index cd25760..5f43918 100644 --- a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist +++ b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist @@ -24,6 +24,7 @@ 2.1.0 DVTPlugInCompatibilityUUIDs + AABB7188-E14E-4433-AD3B-5CD791EAD9A3 9F75337B-21B4-4ADC-B558-F9CADF7073A7 FEC992CC-CA4A-4CFD-8881-77300FCB848A C4A681B0-4A26-480E-93EC-1218098B9AA0 diff --git a/FuzzyAutocomplete/FuzzyAutocomplete.m b/FuzzyAutocomplete/FuzzyAutocomplete.m index 6aecc49..9246026 100644 --- a/FuzzyAutocomplete/FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/FuzzyAutocomplete.m @@ -9,8 +9,11 @@ // Copyright (c) 2014 United Lines of Code. All rights reserved. // +#import + #import "FuzzyAutocomplete.h" #import "FASettings.h" +#import "FAMatchPattern.h" #import "DVTTextCompletionSession+FuzzyAutocomplete.h" #import "DVTTextCompletionListWindowController+FuzzyAutocomplete.h" @@ -24,6 +27,7 @@ + (void)pluginDidLoad:(NSBundle *)plugin { if ([currentApplicationName isEqual:@"Xcode"]) { dispatch_once(&onceToken, ^{ + [self swapClasses]; [self createMenuItem]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationDidFinishLaunching:) @@ -43,6 +47,19 @@ + (void)pluginDidLoad:(NSBundle *)plugin { } } ++ (void) swapClasses { + Class class = NSClassFromString(@"DVTOpenQuicklyPattern"); + if (!class) { + class = NSClassFromString(@"IDEOpenQuicklyPattern"); + } + if (class) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + class_setSuperclass([FAMatchPattern class], class); +#pragma clang diagnostic pop + } +} + + (void) pluginEnabledOrDisabled: (NSNotification *) notification { if (notification.object == [FASettings currentSettings]) { [self swizzleMethods]; diff --git a/XcodeHeaders/IDEOpenQuicklyPattern.h b/XcodeHeaders/IDEOpenQuicklyPattern.h deleted file mode 100644 index d7a09b4..0000000 --- a/XcodeHeaders/IDEOpenQuicklyPattern.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Generated by class-dump 3.4 (64 bit). - * - * class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2012 by Steve Nygard. - */ - -@interface IDEOpenQuicklyPattern : NSObject -{ - NSString *_pattern; - BOOL _patternHasSeparators; - char *_charactersInPattern; - unsigned short *_patternCharacters; - unsigned short *_lowerCasePatternCharacters; - unsigned long long _patternLength; -} - -+ (id)patternWithInput:(id)arg1; -+ (void)initialize; -@property(readonly) NSString *pattern; // @synthesize pattern=_pattern; -- (double)scoreCandidate:(id)arg1 matchedRanges:(id *)arg2; -- (id)matchedRanges:(id)arg1; -- (double)scoreCandidate:(id)arg1; -- (BOOL)matchesCandidate:(id)arg1; -- (BOOL)matchesEverythingMatchedBy:(id)arg1; -- (BOOL)rejectsEverything; -- (id)description; -- (BOOL)isEqual:(id)arg1; -- (BOOL)isEqualToPattern:(id)arg1; -- (unsigned long long)hash; -- (id)copyWithZone:(struct _NSZone *)arg1; -- (void)dealloc; -- (id)initWithPattern:(id)arg1; - -@end - From 853571b6f6f49ffa64b2dc0bc8498eebdfa6a3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20=C5=9Ala=C5=BCy=C5=84ski?= Date: Tue, 9 Jun 2015 00:33:01 +0200 Subject: [PATCH 07/20] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 081b04d..d51b730 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # ![Fz](https://avatars3.githubusercontent.com/u/7301270?s=25) Fuzzy Autocomplete for Xcode +## Xcode 7 support + +Most things seem to work. To try out the plugin in Xcode 7, clone the `xcode7` branch and build the plugin. And please do file any encountered issues on github. + +Install via Alcatraz and/or binary release coming soon. + ## `FuzzyAutocomplete 2.1` This is a Xcode 5+ plugin that patches the autocomplete filter to work the same way the **Open Quickly** works. It performs very well, and the fuzzy matching actually uses Xcode's own `IDEOpenQuicklyPattern`. From 142979ffe09873d7750408501a53b4c32ad700f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Tue, 9 Jun 2015 01:03:31 +0200 Subject: [PATCH 08/20] Work around cornerRadius property no longer being present on text completion window. --- FuzzyAutocomplete/FATextCompletionListHeaderView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/FATextCompletionListHeaderView.m b/FuzzyAutocomplete/FATextCompletionListHeaderView.m index 8453cbf..7989b3f 100644 --- a/FuzzyAutocomplete/FATextCompletionListHeaderView.m +++ b/FuzzyAutocomplete/FATextCompletionListHeaderView.m @@ -81,7 +81,12 @@ - (void)updateWithDataFromSession:(DVTTextCompletionSession *)session { } static inline void drawRectHelper(NSView * view, NSRect dirtyRect) { - CGFloat radius = [[view.window valueForKey: @"cornerRadius"] doubleValue]; + CGFloat radius; + @try { + radius = [[view.window valueForKey: @"cornerRadius"] doubleValue]; + } @catch (NSException * e) { + radius = 8.0; + } NSRect rect = [view.window.contentView convertRect: [view.window.contentView bounds] toView: view]; [[NSColor controlBackgroundColor] setFill]; From 031026e39be16c98c5d2c17d38c8dd4ec663ac5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Tue, 9 Jun 2015 22:01:32 +0200 Subject: [PATCH 09/20] Clean up UUIDs list --- .../FuzzyAutocomplete-Info.plist | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist index 5f43918..84f0556 100644 --- a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist +++ b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist @@ -24,17 +24,18 @@ 2.1.0 DVTPlugInCompatibilityUUIDs - AABB7188-E14E-4433-AD3B-5CD791EAD9A3 - 9F75337B-21B4-4ADC-B558-F9CADF7073A7 - FEC992CC-CA4A-4CFD-8881-77300FCB848A - C4A681B0-4A26-480E-93EC-1218098B9AA0 - AD68E85B-441B-4301-B564-A45E4919A6AD - A2E4D43F-41F4-4FB9-BB94-7177011C9AED - 640F884E-CE55-4B40-87C0-8869546CAB7A - 37B30044-3B14-46BA-ABAA-F01000C27B63 - 992275C1-432A-4CF7-B659-D84ED6D42D3F - A16FF353-8441-459E-A50C-B071F53F51B7 - E969541F-E6F9-4D25-8158-72DC3545A6C6 + 37B30044-3B14-46BA-ABAA-F01000C27B63 + 640F884E-CE55-4B40-87C0-8869546CAB7A + A2E4D43F-41F4-4FB9-BB94-7177011C9AED + AD68E85B-441B-4301-B564-A45E4919A6AD + C4A681B0-4A26-480E-93EC-1218098B9AA0 + FEC992CC-CA4A-4CFD-8881-77300FCB848A + A16FF353-8441-459E-A50C-B071F53F51B7 + 992275C1-432A-4CF7-B659-D84ED6D42D3F + 9F75337B-21B4-4ADC-B558-F9CADF7073A7 + E969541F-E6F9-4D25-8158-72DC3545A6C6 + 8DC44374-2B35-4C57-A6FE-2AD66A36AAD9 + AABB7188-E14E-4433-AD3B-5CD791EAD9A3 FAReportIssueURL https://github.com/FuzzyAutocomplete/FuzzyAutocompletePlugin/issues From 417d3a1cd5e7de038039ff7d04b6d4b8118be28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Tue, 9 Jun 2015 22:44:55 +0200 Subject: [PATCH 10/20] Add missing UUID for 6.4 B4 --- FuzzyAutocomplete/FuzzyAutocomplete-Info.plist | 1 + 1 file changed, 1 insertion(+) diff --git a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist index 84f0556..1f493da 100644 --- a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist +++ b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist @@ -35,6 +35,7 @@ 9F75337B-21B4-4ADC-B558-F9CADF7073A7 E969541F-E6F9-4D25-8158-72DC3545A6C6 8DC44374-2B35-4C57-A6FE-2AD66A36AAD9 + 5EDAC44F-8E0B-42C9-9BEF-E9C12EEC4949 AABB7188-E14E-4433-AD3B-5CD791EAD9A3 FAReportIssueURL From 9b0bf45527cc0271dd3dbaf69a2643afe47694e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 28 Jun 2015 16:37:29 +0200 Subject: [PATCH 11/20] Remove ascending order sorting for _filteredCompletionsPriority Fixes #80 --- ...TTextCompletionSession+FuzzyAutocomplete.m | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m index 3bc53b2..ee09da3 100644 --- a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m @@ -224,10 +224,10 @@ - (void) _fa_selectNextPreviousByPriority: (BOOL) next { NSArray * sorted = nil; NSDictionary * filteredScores = self.fa_scoresForFilteredCompletions; if ([FASettings currentSettings].sortByScore) { - sorted = self.filteredCompletionsAlpha.reverseObjectEnumerator.allObjects; + sorted = self.filteredCompletionsAlpha; } else if (filteredScores) { sorted = [self.filteredCompletionsAlpha sortedArrayWithOptions: NSSortConcurrent - usingComparator: [self _fa_itemComparatorByScores: filteredScores reverse: NO]]; + usingComparator: [self _fa_itemComparatorByScores: filteredScores]]; } [self setValue: sorted forKey: @"_filteredCompletionsPriority"]; } @@ -485,7 +485,7 @@ - (NSUInteger) _fa_getSelectionForFilteringResults: (FAFilteringResults *) resul if (lastRange.location == lastRangePrev.location && lastRange.length >= lastRangePrev.length) { NSComparator comparator = nil; if ([FASettings currentSettings].sortByScore) { - comparator = [self _fa_itemComparatorByScores: results.scores reverse: YES]; + comparator = [self _fa_itemComparatorByScores: results.scores]; } else { comparator = [self _fa_itemComparatorByName]; } @@ -615,7 +615,7 @@ - (FAFilteringResults *)_fa_calculateResultsForQuery: (NSString *) query { NAMED_TIMER_START(SortByScore); if ([FASettings currentSettings].sortByScore) { - [filteredList sortWithOptions: NSSortConcurrent usingComparator: [self _fa_itemComparatorByScores: filteredScores reverse: YES]]; + [filteredList sortWithOptions: NSSortConcurrent usingComparator: [self _fa_itemComparatorByScores: filteredScores]]; } NAMED_TIMER_STOP(SortByScore); @@ -886,18 +886,11 @@ - (NSComparator) _fa_itemComparatorByName { } // gets a comparator for given scores dictionary -- (NSComparator) _fa_itemComparatorByScores: (NSDictionary *) filteredScores reverse: (BOOL) reverse { - if (!reverse) { - return ^(id obj1, id obj2) { - NSComparisonResult result = [filteredScores[obj1.name] compare: filteredScores[obj2.name]]; - return result == NSOrderedSame ? [obj2.name caseInsensitiveCompare: obj1.name] : result; - }; - } else { - return ^(id obj1, id obj2) { - NSComparisonResult result = [filteredScores[obj2.name] compare: filteredScores[obj1.name]]; - return result == NSOrderedSame ? [obj1.name caseInsensitiveCompare: obj2.name] : result; - }; - } +- (NSComparator) _fa_itemComparatorByScores: (NSDictionary *) filteredScores { + return ^(id obj1, id obj2) { + NSComparisonResult result = [filteredScores[obj2.name] compare: filteredScores[obj1.name]]; + return result == NSOrderedSame ? [obj1.name caseInsensitiveCompare: obj2.name] : result; + }; } - (void)_fa_debugCompletionsByScore:(NSArray *)completions withQuery:(NSString *)query { From 849135667bca76d27b282da4fc6f8dea363f04c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Thu, 10 Sep 2015 00:33:43 +0200 Subject: [PATCH 12/20] Add 7.0 GM UUID --- FuzzyAutocomplete/FuzzyAutocomplete-Info.plist | 1 + 1 file changed, 1 insertion(+) diff --git a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist index 8abc7d1..f0ca25f 100644 --- a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist +++ b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist @@ -38,6 +38,7 @@ 5EDAC44F-8E0B-42C9-9BEF-E9C12EEC4949 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 AABB7188-E14E-4433-AD3B-5CD791EAD9A3 + 0420B86A-AA43-4792-9ED0-6FE0F2B16A13 FAReportIssueURL https://github.com/FuzzyAutocomplete/FuzzyAutocompletePlugin/issues From 343957f80cdbd952955d467b1f78ec24682985da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 14:20:56 +0200 Subject: [PATCH 13/20] Add support for Xcode 7.1 Beta --- FuzzyAutocomplete/FuzzyAutocomplete-Info.plist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist index f0ca25f..524a64b 100644 --- a/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist +++ b/FuzzyAutocomplete/FuzzyAutocomplete-Info.plist @@ -38,7 +38,8 @@ 5EDAC44F-8E0B-42C9-9BEF-E9C12EEC4949 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 AABB7188-E14E-4433-AD3B-5CD791EAD9A3 - 0420B86A-AA43-4792-9ED0-6FE0F2B16A13 + 0420B86A-AA43-4792-9ED0-6FE0F2B16A13 + CC0D0F4F-05B3-431A-8F33-F84AFCB2C651 FAReportIssueURL https://github.com/FuzzyAutocomplete/FuzzyAutocompletePlugin/issues From 91df12fdde4c326b6311ad87ee00c7ce22fd961f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 14:23:21 +0200 Subject: [PATCH 14/20] Improve the header view UX - align the header view text with the title column - make the header visible by default - add option to have the header only contain the query - grey out everything except the query "Good artists copy. Great artists steal." --- FuzzyAutocomplete/FASettings.h | 3 ++ FuzzyAutocomplete/FASettings.m | 11 +++-- FuzzyAutocomplete/FASettingsWindow.xib | 42 +++++++------------ .../FATextCompletionListHeaderView.m | 33 ++++++++++++++- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/FuzzyAutocomplete/FASettings.h b/FuzzyAutocomplete/FASettings.h index 8805d4c..7fb6e04 100644 --- a/FuzzyAutocomplete/FASettings.h +++ b/FuzzyAutocomplete/FASettings.h @@ -63,6 +63,9 @@ extern NSString * FASettingsPluginEnabledDidChangeNotification; /// Should the list header be visible. @property (nonatomic, readonly) BOOL showListHeader; +/// Should the list header contain number of matches. +@property (nonatomic, readonly) BOOL showNumMatches; + /// Should the timing in the list header be visible. @property (nonatomic, readonly) BOOL showTiming; diff --git a/FuzzyAutocomplete/FASettings.m b/FuzzyAutocomplete/FASettings.m index 3479582..4386a64 100644 --- a/FuzzyAutocomplete/FASettings.m +++ b/FuzzyAutocomplete/FASettings.m @@ -13,7 +13,7 @@ NSString * FASettingsPluginEnabledDidChangeNotification = @"io.github.FuzzyAutocomplete.PluginEnabledDidChange"; // increment to show settings screen to the user -static const NSUInteger kSettingsVersion = 3; +static const NSUInteger kSettingsVersion = 4; @interface FASettings () @@ -107,7 +107,8 @@ - (void) windowWillClose: (NSNotification *) notification { static const BOOL kDefaultShowScores = NO; static const BOOL kDefaultShowInlinePreview = YES; static const BOOL kDefaultHideCursorInNonPrefixPreview = NO; -static const BOOL kDefaultShowListHeader = NO; +static const BOOL kDefaultShowListHeader = YES; +static const BOOL kDefaultShowNumMatches = NO; static const BOOL kDefaultNormalizeScores = NO; static const BOOL kDefaultShowTiming = NO; static NSString * const kDefaultScoreFormat = @"* #0.00"; @@ -134,6 +135,7 @@ - (IBAction)resetDefaults:(id)sender { self.scoreFormat = kDefaultScoreFormat; self.normalizeScores = kDefaultNormalizeScores; self.showListHeader = kDefaultShowListHeader; + self.showNumMatches = kDefaultShowNumMatches; self.showInlinePreview = kDefaultShowInlinePreview; self.hideCursorInNonPrefixPreview = kDefaultHideCursorInNonPrefixPreview; self.showTiming = kDefaultShowTiming; @@ -178,6 +180,7 @@ - (void) loadFromDefaults { loadNumber(showInlinePreview, ShowInlinePreview); loadNumber(hideCursorInNonPrefixPreview, HideCursorInNonPrefixPreview); loadNumber(showListHeader, ShowListHeader); + loadNumber(showNumMatches, ShowNumMatches); loadNumber(showTiming, ShowTiming); loadNumber(prefixAnchor, PrefixAnchor); @@ -223,7 +226,8 @@ - (void) migrateSettingsFromVersion:(NSUInteger)version { break; case 1: // dont break, fall through to higher cases case 2: - ; + case 3: + self.showListHeader = YES; } } @@ -258,6 +262,7 @@ - (void) set ## Name: (type) name { \ BOOL_SETTINGS_SETTER(showInlinePreview, ShowInlinePreview) BOOL_SETTINGS_SETTER(hideCursorInNonPrefixPreview, HideCursorInNonPrefixPreview) BOOL_SETTINGS_SETTER(showListHeader, ShowListHeader) +BOOL_SETTINGS_SETTER(showNumMatches, ShowNumMatches) BOOL_SETTINGS_SETTER(showTiming, ShowTiming) BOOL_SETTINGS_SETTER(correctLetterCase, CorrectLetterCase); BOOL_SETTINGS_SETTER(correctLetterCaseBestMatchOnly, CorrectLetterCaseBestMatchOnly); diff --git a/FuzzyAutocomplete/FASettingsWindow.xib b/FuzzyAutocomplete/FASettingsWindow.xib index 6b802b0..3ccabfb 100644 --- a/FuzzyAutocomplete/FASettingsWindow.xib +++ b/FuzzyAutocomplete/FASettingsWindow.xib @@ -1,9 +1,9 @@ - + - + @@ -89,9 +89,6 @@ - - - @@ -139,6 +136,18 @@ + @@ -165,7 +174,7 @@ - If enabled, the completion list will have an additional header showing the query, number of matches (all and visible) [and time spent on scoring]. + If enabled, the completion list will have a header showing the query, optionally it can also show number of matches [and time spent on scoring]. @@ -212,9 +221,6 @@ NOTE: items can reappear when their score rises above the threshold. - - - @@ -307,9 +313,6 @@ NOTE: items can reappear when their score rises above the threshold. - - - @@ -334,9 +337,6 @@ NOTE: items can reappear when their score rises above the threshold. - - - @@ -361,9 +361,6 @@ NOTE: items can reappear when their score rises above the threshold. - - - @@ -388,9 +385,6 @@ NOTE: items can reappear when their score rises above the threshold. - - - @@ -497,9 +491,6 @@ Especially useful for adjusting the threshold and debugging. - - - @@ -670,9 +661,6 @@ Prefix - maximum bonus factor for prefix matches - - - diff --git a/FuzzyAutocomplete/FATextCompletionListHeaderView.m b/FuzzyAutocomplete/FATextCompletionListHeaderView.m index 7989b3f..37b81c9 100644 --- a/FuzzyAutocomplete/FATextCompletionListHeaderView.m +++ b/FuzzyAutocomplete/FATextCompletionListHeaderView.m @@ -15,6 +15,7 @@ @implementation FATextCompletionListHeaderView { NSBox * _divider; NSTextField * _label; NSFont * _boldFont; + BOOL _showCount; BOOL _showFilteredCount; BOOL _showTiming; } @@ -29,6 +30,7 @@ - (id)initWithFrame:(NSRect)frame { _label.drawsBackground = NO; _label.bordered = NO; _label.bezeled = NO; + _label.textColor = [NSColor disabledControlTextColor]; DVTFontAndColorTheme * theme = [DVTFontAndColorTheme currentTheme]; _label.font = theme.sourcePlainTextFont; _boldFont = [[NSFontManager sharedFontManager] convertFont: _label.font toHaveTrait: NSFontBoldTrait]; @@ -40,7 +42,8 @@ - (id)initWithFrame:(NSRect)frame { _divider.borderWidth = 0.5; _divider.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin; [self addSubview: _divider]; - _showFilteredCount = [FASettings currentSettings].filterByScore; + _showCount = [FASettings currentSettings].showNumMatches; + _showFilteredCount = _showCount && [FASettings currentSettings].filterByScore; _showTiming = [FASettings currentSettings].showTiming; } return self; @@ -58,6 +61,29 @@ - (void)mouseUp:(NSEvent *)theEvent { } +- (void)onColumnsResized:(NSNotification *) notification { + NSInteger titleColumn = [self.tableView columnWithIdentifier: @"title"]; + if (titleColumn != -1) { + [_label setFrame: [self headerRectOfColumn: titleColumn]]; + } else { + RLog(@"Could not find title column."); + } +} + +-(void)setTableView:(NSTableView *)tableView { + [[NSNotificationCenter defaultCenter] removeObserver: self + name: NSTableViewColumnDidResizeNotification + object: self.tableView]; + [super setTableView: tableView]; + if (!tableView) { + return; + } + [[NSNotificationCenter defaultCenter] addObserver: self + selector: @selector(onColumnsResized:) + name: NSTableViewColumnDidResizeNotification + object: tableView]; +} + - (void)updateWithDataFromSession:(DVTTextCompletionSession *)session { NSString * status; @@ -67,8 +93,10 @@ - (void)updateWithDataFromSession:(DVTTextCompletionSession *)session { if (_showFilteredCount && shownMatches != allMatches) { status = [NSString stringWithFormat: @"%@ - %ld match%s (%ld shown)", prefix, allMatches, allMatches == 1 ? "" : "es", shownMatches]; - } else { + } else if (_showCount) { status = [NSString stringWithFormat: @"%@ - %ld match%s", prefix, shownMatches, shownMatches == 1 ? "" : "es"]; + } else { + status = prefix; } if (_showTiming) { status = [status stringByAppendingFormat: @" - %.2f ms", 1000 * session.fa_lastFilteringTime]; @@ -76,6 +104,7 @@ - (void)updateWithDataFromSession:(DVTTextCompletionSession *)session { NSMutableAttributedString * attributed = [[NSMutableAttributedString alloc] initWithString: status]; [attributed addAttribute: NSFontAttributeName value: _boldFont range: NSMakeRange(0, session.fa_filteringQuery.length)]; + [attributed addAttribute: NSForegroundColorAttributeName value: [NSColor controlTextColor] range: NSMakeRange(0, session.fa_filteringQuery.length)]; [_label setAttributedStringValue: attributed]; } From 48d10befcf17725c26e06b1cd2655d17d0a6bfbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 17:18:05 +0200 Subject: [PATCH 15/20] Avoid `nil` in dictionary literals --- .../DVTTextCompletionListWindowController+FuzzyAutocomplete.m | 4 ++-- .../DVTTextCompletionSession+FuzzyAutocomplete.m | 4 ++-- FuzzyAutocomplete/FATheme.m | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m index d73c8ee..daa4274 100644 --- a/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m @@ -226,10 +226,10 @@ - (void) _fa_getTitleColumnWidth:(double *)titleWidth typeColumnWidth:(double *) - (CGFloat) _fa_widthForScoreColumn { NSTableView * tableView = [self valueForKey: @"_completionsTableView"]; NSTableColumn * scoreColumn = [tableView tableColumnWithIdentifier: @"score"]; - if (scoreColumn && self.session.fa_nonZeroScores) { + DVTFontAndColorTheme * theme = [DVTFontAndColorTheme currentTheme]; + if (scoreColumn && self.session.fa_nonZeroScores && theme.sourcePlainTextFont) { NSNumberFormatter * formatter = ((NSCell *)scoreColumn.dataCell).formatter; NSString * sampleValue = [formatter stringFromNumber: @0]; - DVTFontAndColorTheme * theme = [DVTFontAndColorTheme currentTheme]; NSDictionary * attributes = @{ NSFontAttributeName : theme.sourcePlainTextFont }; return [[NSAttributedString alloc] initWithString: sampleValue attributes: attributes].size.width + 6; } else { diff --git a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m index ee09da3..e32282d 100644 --- a/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m @@ -902,8 +902,8 @@ - (void)_fa_debugCompletionsByScore:(NSArray *)completions withQuery:(NSString * double matchScore = [pattern scoreCandidate: item.name matchedRanges: &ranges]; double factor = [self _priorityFactorForItem: item]; [completionsWithScore addObject:@{ - @"item" : item.name, - @"ranges" : ranges ? ranges : @[], + @"item" : item.name ?: @"", + @"ranges" : ranges ?: @[], @"factor" : @(factor), @"priority" : @(item.priority), @"matchScore" : @(matchScore), diff --git a/FuzzyAutocomplete/FATheme.m b/FuzzyAutocomplete/FATheme.m index d6e4b22..29dda68 100644 --- a/FuzzyAutocomplete/FATheme.m +++ b/FuzzyAutocomplete/FATheme.m @@ -49,7 +49,7 @@ - (void)loadFromTheme:(DVTFontAndColorTheme *)theme { - (void) loadPreviewAttributesFromTheme: (DVTFontAndColorTheme *) theme { self.previewTextAttributesForNotMatchedRanges = @{ - NSForegroundColorAttributeName : theme.sourceTextCompletionPreviewColor, + NSForegroundColorAttributeName : theme.sourceTextCompletionPreviewColor ?: [NSColor disabledControlTextColor], }; } From 9fb9dc896dbdbf12b288650d6beb9beb8bb07f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 18:55:00 +0200 Subject: [PATCH 16/20] Fix-up the new setting bindings --- FuzzyAutocomplete/FASettingsWindow.xib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/FASettingsWindow.xib b/FuzzyAutocomplete/FASettingsWindow.xib index 3ccabfb..5c4fd38 100644 --- a/FuzzyAutocomplete/FASettingsWindow.xib +++ b/FuzzyAutocomplete/FASettingsWindow.xib @@ -144,7 +144,7 @@ - + From e66a2214b55ce6159c59a460728dfcaadf801e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 19:02:57 +0200 Subject: [PATCH 17/20] Deregister the header view from `NSNotificationCenter` on `dealloc` --- FuzzyAutocomplete/FATextCompletionListHeaderView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FuzzyAutocomplete/FATextCompletionListHeaderView.m b/FuzzyAutocomplete/FATextCompletionListHeaderView.m index 37b81c9..5aff237 100644 --- a/FuzzyAutocomplete/FATextCompletionListHeaderView.m +++ b/FuzzyAutocomplete/FATextCompletionListHeaderView.m @@ -49,6 +49,10 @@ - (id)initWithFrame:(NSRect)frame { return self; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver: self]; +} + - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { return NO; } From 30af5003414dcd10fa5f91cc9f9719ec562e6829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 19:17:47 +0200 Subject: [PATCH 18/20] Fix the title column x alignment when score column is disabled. --- .../DVTTextCompletionListWindowController+FuzzyAutocomplete.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m b/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m index daa4274..942440c 100644 --- a/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m +++ b/FuzzyAutocomplete/DVTTextCompletionListWindowController+FuzzyAutocomplete.m @@ -145,7 +145,9 @@ - (void) _fa_updateCurrentDisplayState { // We modify titleColumnX with score column's width, so that title column is aligned with typed text - (CGRect) _fa_preferredWindowFrameForTextFrame: (CGRect) textFrame columnsWidth: (double *) widths titleColumnX: (double) titleX { NSTableView * tableView = [self valueForKey: @"_completionsTableView"]; - return [self _fa_preferredWindowFrameForTextFrame: textFrame columnsWidth: widths titleColumnX: titleX + [self _fa_widthForScoreColumn] + tableView.intercellSpacing.width]; + NSTableColumn * scoreColumn = [tableView tableColumnWithIdentifier: @"score"]; + CGFloat additionalWidth = scoreColumn ? [self _fa_widthForScoreColumn] + tableView.intercellSpacing.width : 0; + return [self _fa_preferredWindowFrameForTextFrame: textFrame columnsWidth: widths titleColumnX: titleX + additionalWidth]; } From 731b19c7176a1c7032a7655405d6c545b2d3779d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 19:51:57 +0200 Subject: [PATCH 19/20] Fix header trimming when title column is reported too narrow (Seems at this point it can be reported narrower than it actually will end up being...) --- FuzzyAutocomplete/FATextCompletionListHeaderView.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FuzzyAutocomplete/FATextCompletionListHeaderView.m b/FuzzyAutocomplete/FATextCompletionListHeaderView.m index 5aff237..d17f805 100644 --- a/FuzzyAutocomplete/FATextCompletionListHeaderView.m +++ b/FuzzyAutocomplete/FATextCompletionListHeaderView.m @@ -68,7 +68,11 @@ - (void)mouseUp:(NSEvent *)theEvent { - (void)onColumnsResized:(NSNotification *) notification { NSInteger titleColumn = [self.tableView columnWithIdentifier: @"title"]; if (titleColumn != -1) { - [_label setFrame: [self headerRectOfColumn: titleColumn]]; + NSRect labelFrame = [self.tableView rectOfColumn: titleColumn]; + labelFrame.origin.y = 0; + labelFrame.size.height = self.bounds.size.height; + labelFrame.size.width = self.bounds.size.width - labelFrame.origin.x; + [_label setFrame: labelFrame]; } else { RLog(@"Could not find title column."); } From 62d285d876ddd2379e5f6f50d2abf85f5546e415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20S=CC=81laz=CC=87yn=CC=81ski?= Date: Sun, 13 Sep 2015 20:07:09 +0200 Subject: [PATCH 20/20] Account for the cell padding in the header --- FuzzyAutocomplete/FATextCompletionListHeaderView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/FuzzyAutocomplete/FATextCompletionListHeaderView.m b/FuzzyAutocomplete/FATextCompletionListHeaderView.m index d17f805..920aa0b 100644 --- a/FuzzyAutocomplete/FATextCompletionListHeaderView.m +++ b/FuzzyAutocomplete/FATextCompletionListHeaderView.m @@ -69,6 +69,7 @@ - (void)onColumnsResized:(NSNotification *) notification { NSInteger titleColumn = [self.tableView columnWithIdentifier: @"title"]; if (titleColumn != -1) { NSRect labelFrame = [self.tableView rectOfColumn: titleColumn]; + labelFrame.origin.x += 1; labelFrame.origin.y = 0; labelFrame.size.height = self.bounds.size.height; labelFrame.size.width = self.bounds.size.width - labelFrame.origin.x;