diff options
-rw-r--r-- | Source/SPTextView.m | 54 | ||||
-rw-r--r-- | Source/SPTextViewAdditions.m | 6 |
2 files changed, 40 insertions, 20 deletions
diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 734949f1..82bfdedf 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -2341,7 +2341,14 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) - (void)moveWordRight:(id)sender { [super moveWordRight:sender]; - while([self selectedRange].location < [[[self textStorage] string] length] && [[[self textStorage] string] characterAtIndex:[self selectedRange].location] == '.') + NSCharacterSet *whiteSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + while([self selectedRange].location < [[[self textStorage] string] length] + && ([[[self textStorage] string] characterAtIndex:[self selectedRange].location] == '.' + || ( + [[[self textStorage] string] characterAtIndex:[self selectedRange].location-1] == '.' + && ![whiteSet characterIsMember:[[[self textStorage] string] characterAtIndex:[self selectedRange].location]] + ) + )) [super moveWordRight:sender]; } @@ -2362,22 +2369,41 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) - (void)moveWordRightAndModifySelection:(id)sender { [super moveWordRightAndModifySelection:sender]; - while(NSMaxRange([self selectedRange]) < [[[self textStorage] string] length] && [[[self textStorage] string] characterAtIndex:NSMaxRange([self selectedRange])] == '.') + NSCharacterSet *whiteSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + while(NSMaxRange([self selectedRange]) < [[[self textStorage] string] length] + && ([[[self textStorage] string] characterAtIndex:NSMaxRange([self selectedRange])] == '.' + || ( + [[[self textStorage] string] characterAtIndex:NSMaxRange([self selectedRange])-1] == '.' + && ![whiteSet characterIsMember:[[[self textStorage] string] characterAtIndex:NSMaxRange([self selectedRange])]] + ) + )) [super moveWordRightAndModifySelection:sender]; } - (void) deleteBackward:(id)sender { - // If the caret is currently inside a marked auto-pair, delete the characters on both sides - // of the caret. NSRange currentRange = [self selectedRange]; - if (currentRange.length == 0 && currentRange.location > 0 && [self areAdjacentCharsLinked]) - [self setSelectedRange:NSMakeRange(currentRange.location - 1,2)]; - // Avoid auto-uppercasing if resulting word would be a SQL keyword; - // e.g. type inta| and deleteBackward: - delBackwardsWasPressed = YES; + if (currentRange.length == 0) { + + // If the caret is currently inside a marked auto-pair, delete the characters on both sides + // of the caret. + if (currentRange.location > 0 && [self areAdjacentCharsLinked]) { + [self setSelectedRange:NSMakeRange(currentRange.location - 1,2)]; + // Avoid auto-uppercasing if resulting word would be a SQL keyword; + // e.g. type inta| and deleteBackward: + delBackwardsWasPressed = YES; + } + + // Remove soft indent if active and left from caret are only white spaces + else if ([prefs boolForKey:SPCustomQuerySoftIndent] && [self isCaretAtIndentPositionIgnoreLineStart:NO]) + { + [self shiftSelectionLeft]; + return; + } + + } [super deleteBackward:sender]; @@ -2431,16 +2457,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } // Remove soft indent if active and left from caret are only white spaces - if (aSelector == @selector(deleteBackward:) - && ![self selectedRange].length - && [prefs boolForKey:SPCustomQuerySoftIndent] - && [self isCaretAtIndentPositionIgnoreLineStart:NO]) - { - [self shiftSelectionLeft]; - return; - } - - // Remove soft indent if active and left from caret are only white spaces if (aSelector == @selector(deleteForward:) && ![self selectedRange].length && [prefs boolForKey:SPCustomQuerySoftIndent] diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 6723fa7f..9cefa758 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -63,7 +63,11 @@ end++; } - return(NSMakeRange(start, end-start)); + NSRange wordRange = NSMakeRange(start, end-start); + if(wordRange.length && [[self string] characterAtIndex:NSMaxRange(wordRange)-1] == '.') + wordRange.length--; + + return(wordRange); } |