Skip to content

Commit

Permalink
Merge branch 'release/2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mjdescy committed Mar 23, 2016
2 parents 3a39095 + 4bb0227 commit 7b7bc46
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 21 deletions.
76 changes: 69 additions & 7 deletions TodoTxtMac/TTMFieldEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,35 @@ - (void)doCompletion:(NSTimer*)timer {
* addresses (with "@").
*/
- (void)keyUp:(NSEvent*)event {
// Start the completion timer if the user types an "@" or "+".
if ([[event characters] isEqualToString:@"@"] || [[event characters] isEqualToString:@"+"]) {
[self startCompletionTimer];
} else {
[self stopCompletionTimer];
// Start the completion timer if the range for user completion starts with "@" or "+".
NSString *partialRange = [[self string] substringWithRange:self.rangeForUserCompletion];
if ([partialRange hasPrefix:@"@"] || [partialRange hasPrefix:@"+"]) {

// Don't trigger autocompletion time if user is pressing a deletion key or pressing Enter
unichar keyChar = [self keyCharFromEvent:event];
if (![self keyCharIsADeletionKey:keyChar] && ![self keyCharIsEnterKey:keyChar]) {
[self startCompletionTimer];
}
}

// Call the super so we don't override any other behaviors.
[super keyUp:event];
}

- (BOOL)keyCharIsADeletionKey:(unichar)keyChar {
return (keyChar == NSBackspaceCharacter || keyChar == NSDeleteCharacter);
}

- (BOOL)keyCharIsEnterKey:(unichar)keyChar {
return (keyChar == NSEnterCharacter || keyChar == '\r');
}

- (unichar)keyCharFromEvent:(NSEvent*)event {
NSString *passedChar = [event charactersIgnoringModifiers];
unichar keyChar = [passedChar characterAtIndex:0];
return keyChar;
}

/*!
* @method completionsForPartialWordRange:indexOfSelectedItem:
* @abstract This method returns autocompletion suggestions based on the range it receives.
Expand All @@ -130,16 +148,31 @@ - (NSArray*)completionsForPartialWordRange:(NSRange)charRange
NSString *partialString = [[self string] substringWithRange:charRange];

if ([partialString hasPrefix:@"+"]) {
return self.projectsArray;
return [self partialCompletionsFromSourceArray:self.projectsArray partialString:partialString];
} else if ([partialString hasPrefix:@"@"]) {
return self.contextsArray;
return [self partialCompletionsFromSourceArray:self.contextsArray partialString:partialString];
} else {
// Call the super method to get the default behavior.
// This allows for the user to type Esc and still trigger autocompletion.
return [super completionsForPartialWordRange:charRange indexOfSelectedItem:index];
}
}

- (NSArray*)partialCompletionsFromSourceArray:(NSArray*)sourceArray
partialString:(NSString*)partialString{
if (sourceArray == nil) {
return nil;
}

NSMutableArray *returnArray = [[NSMutableArray alloc] init];
for (NSString *str in sourceArray) {
if ([[str uppercaseString] hasPrefix:[partialString uppercaseString]]) {
[returnArray addObject:str];
}
}
return returnArray;
}

/*!
* @method rangeForUserCompletion:
* @abstract This method returns the range to be replaced by autocompletion.
Expand All @@ -161,9 +194,38 @@ - (NSRange)rangeForUserCompletion {
superRange.length = 1;
}

// Look 1 character back from the superRange.
// If it is a "@" or "+", extend the superRange back to include that character.
// This is necessary for autocompletion to work properly for contexts and projects.
NSString *leadingCharacter = [self leadingCharacterToLeftOfRange:superRange];
if ([leadingCharacter isEqualToString:@"@"] || [leadingCharacter isEqualToString:@"+"]) {
if (superRange.location > 0) {
superRange.location -= 1;
superRange.length += 1;
}
}

return superRange;
}

- (NSString*)leadingCharacterToLeftOfRange:(NSRange)range {
if (range.location == 0) {
return [[self string] substringWithRange:range];
}

NSRange newRange = NSMakeRange(range.location - 1, 1);
return [[self string] substringWithRange:newRange];
}

- (NSString*)stringForRangeWithAdditionalLeadingCharacter:(NSRange)range {
if (range.location == 0) {
return [[self string] substringWithRange:range];
}

NSRange newRange = NSMakeRange(range.location - 1, range.length + 1);
return [[self string] substringWithRange:newRange];
}

/*!
* @method: cancelOperation:
* @abstract This method undoes all changes of the text field being edited when the user hits Esc,
Expand Down
22 changes: 11 additions & 11 deletions TodoTxtMac/TTMFilters.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="TTMFiltersController">
Expand Down Expand Up @@ -524,7 +524,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="tcy-Zc-P6i">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -1016,7 +1016,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="vAx-J9-pQC">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -1508,7 +1508,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="ues-cY-hv0">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -2000,7 +2000,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="Dn2-oy-WkD">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -2492,7 +2492,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="Xch-za-6Nr">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -2984,7 +2984,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="2bq-D6-2te">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -3476,7 +3476,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="JkQ-8M-KaS">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -3968,7 +3968,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="h5H-Ye-21u">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -4460,7 +4460,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="uW2-e6-tfL">
<rect key="frame" x="477" y="1" width="15" height="258"/>
<rect key="frame" x="476" y="1" width="16" height="258"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down
2 changes: 1 addition & 1 deletion TodoTxtMac/TTMTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ - (void)keyDown:(NSEvent *)theEvent {

// update task (send Enter/Return to super)
if (keyChar == NSEnterCharacter || keyChar == '\r' || keyChar == 'u') {
[self translateKeyDownEvent:theEvent toKeyDown:'u' sendToControl:self];
[self translateKeyDownEvent:theEvent toKeyDown:'u' sendToControl:[self window]];
return;
}

Expand Down
4 changes: 2 additions & 2 deletions TodoTxtMac/TodoTxtMac-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>2.1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2006</string>
<string>2010</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 7b7bc46

Please sign in to comment.