Skip to content

Commit e1abbdb

Browse files
committed
Merge pull request #33 from FuzzyAutocomplete/develop
Fuzzy Autocomplete 2.0
2 parents 7bb1c6b + 948301f commit e1abbdb

32 files changed

+2728
-524
lines changed

CHANGELOG.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Changelog
2+
3+
#### 2.0.0 - 2014/04/16
4+
**A major update introducing many fixes and improvements, including:**
5+
6+
* Visual feedback in Completion List and Inline Preview
7+
* Settings Window, settings now don't require Xcode restart
8+
* Option to sort items by match score
9+
* Option to hide items based on threshold
10+
* Option to hide Inline Preview, which now works correctly
11+
* Option to show a List Header with query and number of matches
12+
* Option to show item scores in the List
13+
* Improved score formula, added option to tweak parameters
14+
* Previously hidden items can now re-appear if their score rises
15+
* `Tab` now inserts an useful prefix based on whole fuzzy match
16+
* The results should no longer depend on the speed of typing
17+
* Got rid of order dependent "shortest match" selection mechanism
18+
* Performance++
19+
* UX++
20+
* ...
21+
22+
#### 1.7 - 2014/03/23
23+
24+
* Adds inserting useful prefix with `Tab` as an option.
25+
26+
#### 1.6 - 2014/03/22
27+
28+
* No longer prioritises shortest match by default. Can be re-enabled with `defaults write com.apple.dt.Xcode FuzzyAutocompletePrioritizeShortestMatch -bool yes` and restarting Xcode.
29+
30+
#### 1.5 - 2013/11/05
31+
32+
* Shortest match will always be selected
33+
34+
#### 1.4 - 2013/10/26
35+
36+
* Remove requirement to start fuzzy match with first letter of desired match
37+
* Improve performance by parallelising work
38+
39+
#### 1.3.1 - 2013/10/24
40+
41+
* Decrease the weighting of Xcode's priority factor from `1.0` to `0.2`
42+
* Prepare for [KSImageNamed](https://github.com/ksuther/KSImageNamed-Xcode) compatibility when [KSImageNamed#31](https://github.com/ksuther/KSImageNamed-Xcode/pull/31) gets merged.
43+
44+
#### 1.3 - 2013/10/23
45+
46+
* Now factors in Xcode's learning priority system - [#2](https://github.com/chendo/FuzzyAutocompletePlugin/issues/2)
47+
* `Tab` now accepts selected completion as it doesn't make sense to insert prefix with fuzzy matching
48+
49+
#### 1.2 - 2013/10/22
50+
51+
* Fixes missing file entries when autocompleting paths - [#1](https://github.com/chendo/FuzzyAutocompletePlugin/issues/1)
52+
53+
#### 1.1 - 2013/10/21
54+
55+
* Implement partial completion support via `Tab`
56+
57+
#### 1.0 - 2013/10/20
58+
59+
* Initial release

FuzzyAutocomplete.xcodeproj/project.pbxproj

Lines changed: 66 additions & 10 deletions
Large diffs are not rendered by default.

FuzzyAutocomplete.xcodeproj/xcuserdata/chendo.xcuserdatad/xcschemes/FuzzyAutocomplete.xcscheme

Lines changed: 0 additions & 59 deletions
This file was deleted.

FuzzyAutocomplete.xcodeproj/xcuserdata/chendo.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.h
3+
// FuzzyAutocomplete
4+
//
5+
// Created by Leszek Slazynski on 03/02/2014.
6+
// Copyright (c) 2014 United Lines of Code. All rights reserved.
7+
//
8+
9+
#import "DVTTextCompletionInlinePreviewController.h"
10+
11+
@interface DVTTextCompletionInlinePreviewController (FuzzyAutocomplete)
12+
13+
/// Matched ranges mapped to preview space.
14+
@property (nonatomic, retain) NSArray * fa_matchedRanges;
15+
16+
@end
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m
3+
// FuzzyAutocomplete
4+
//
5+
// Created by Leszek Slazynski on 03/02/2014.
6+
// Copyright (c) 2014 United Lines of Code. All rights reserved.
7+
//
8+
9+
#import "DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.h"
10+
#import "DVTTextCompletionSession.h"
11+
#import "DVTTextCompletionSession+FuzzyAutocomplete.h"
12+
#import "DVTFontAndColorTheme.h"
13+
#import "JRSwizzle.h"
14+
#import <objc/runtime.h>
15+
16+
@implementation DVTTextCompletionInlinePreviewController (FuzzyAutocomplete)
17+
18+
+ (void) load {
19+
[self jr_swizzleMethod: @selector(ghostComplementRange)
20+
withMethod: @selector(_fa_ghostComplementRange)
21+
error: NULL];
22+
23+
[self jr_swizzleMethod: @selector(_showPreviewForItem:)
24+
withMethod: @selector(_fa_showPreviewForItem:)
25+
error: NULL];
26+
}
27+
28+
#pragma mark - overrides
29+
30+
// We added calculation of matchedRanges and ghostRange here.
31+
- (void) _fa_showPreviewForItem: (id<DVTTextCompletionItem>) item {
32+
[self _fa_showPreviewForItem: item];
33+
34+
DVTTextCompletionSession * session = [self valueForKey: @"_session"];
35+
36+
NSArray * ranges = [session fa_matchedRangesForItem: item];
37+
38+
if (!ranges.count) {
39+
self.fa_matchedRanges = nil;
40+
self.fa_overridedGhostRange = nil;
41+
return;
42+
}
43+
44+
NSUInteger previewLength = self.previewRange.length;
45+
NSString *previewText;
46+
47+
if (previewLength == item.completionText.length) {
48+
previewText = item.completionText;
49+
} else if (previewLength == item.name.length) {
50+
previewText = item.name;
51+
} else if (previewLength == item.displayText.length) {
52+
previewText = item.displayText;
53+
} else {
54+
NSTextView * textView = (NSTextView *) session.textView;
55+
previewText = [[textView.textStorage attributedSubstringFromRange: self.previewRange] string];
56+
}
57+
58+
ranges = [session fa_convertRanges: ranges
59+
fromString: item.name
60+
toString: previewText
61+
addOffset: self.previewRange.location];
62+
63+
if (!ranges.count) {
64+
self.fa_overridedGhostRange = nil;
65+
} else {
66+
NSRange lastRange = [[ranges lastObject] rangeValue];
67+
NSUInteger start = NSMaxRange(lastRange);
68+
NSUInteger end = NSMaxRange(self.previewRange);
69+
NSRange override = NSMakeRange(start, end - start);
70+
self.fa_overridedGhostRange = [NSValue valueWithRange: override];
71+
}
72+
73+
self.fa_matchedRanges = ranges;
74+
}
75+
76+
- (NSRange) _fa_ghostComplementRange {
77+
NSValue * override = self.fa_overridedGhostRange;
78+
if (override) {
79+
return [override rangeValue];
80+
}
81+
return [self _fa_ghostComplementRange];
82+
}
83+
84+
#pragma mark - additional properties
85+
86+
static char overrideGhostKey;
87+
static char matchedRangesKey;
88+
89+
- (NSArray *)fa_matchedRanges {
90+
return objc_getAssociatedObject(self, &matchedRangesKey);
91+
}
92+
93+
- (void)setFa_matchedRanges:(NSArray *)array {
94+
objc_setAssociatedObject(self, &matchedRangesKey, array, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
95+
}
96+
97+
// We override the gost range to span only after last matched letter.
98+
// This way we do not need to apply arguments to matched ranges.
99+
- (NSValue *)fa_overridedGhostRange {
100+
return objc_getAssociatedObject(self, &overrideGhostKey);
101+
}
102+
103+
- (void)setFa_overridedGhostRange:(NSValue *)value {
104+
objc_setAssociatedObject(self, &overrideGhostKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
105+
}
106+
107+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// DVTTextCompletionListWindowController+FuzzyAutocomplete.h
3+
// FuzzyAutocomplete
4+
//
5+
// Created by Leszek Slazynski on 01/02/2014.
6+
// Copyright (c) 2014 United Lines of Code. All rights reserved.
7+
//
8+
9+
#import "DVTTextCompletionListWindowController.h"
10+
11+
@interface DVTTextCompletionListWindowController (FuzzyAutocomplete)
12+
13+
@end

0 commit comments

Comments
 (0)