Skip to content

Commit

Permalink
Closes Issue #54: Autocompletion of contexts does not work.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjdescy committed Feb 5, 2015
1 parent 00e6224 commit db331e4
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions TodoTxtMac/TTMFieldEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ - (NSArray*)completionsForPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(NSInteger*)index {
// Check the character range for "@" and "+".
NSString *partialString = [[self string] substringWithRange:charRange];
if ([partialString hasSuffix:@"+"]) {

if ([partialString hasPrefix:@"+"]) {
return self.projectsArray;
} else if ([partialString hasSuffix:@"@"]) {
} else if ([partialString hasPrefix:@"@"]) {
return self.contextsArray;
} else {
// Call the super method to get the default behavior.
Expand All @@ -146,17 +147,15 @@ - (NSArray*)completionsForPartialWordRange:(NSRange)charRange
- (NSRange)rangeForUserCompletion {
// Call the super method to get the default behavior.
NSRange superRange = [super rangeForUserCompletion];

// Only override the default behavior if there is an "@" in the partial range.
NSString *partialString = [[self string] substringWithRange:superRange];
NSRange atSignRange = [partialString rangeOfString:@"@" options:NSBackwardsSearch];
if (atSignRange.location == NSNotFound) {
return superRange;

// For some reason, when triggering autocompletion of contexts, which begin with "@",
// the superRange has a length of 0, which prevents autocompletion from working.
// This conditional code block, which adjusts the range, fixes that.
if (superRange.length == 0 && superRange.location > 0) {
superRange.location -= 1;
superRange.length = 1;
}

// Modify the range properties to just return the "@" at the end of the range.
superRange.location = superRange.location + atSignRange.location;
superRange.length = 1;
return superRange;
}

Expand Down

0 comments on commit db331e4

Please sign in to comment.