aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTextViewAdditions.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r--Source/SPTextViewAdditions.m15
1 files changed, 13 insertions, 2 deletions
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 38560b31..dc3d4c16 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -49,10 +49,21 @@
if(curLocation < newStartRange || curLocation > newEndRange)
{
[self setSelectedRange:curRange];
- [self moveWordRightAndModifySelection:self];
+ [self moveWordRight:self];
+ [self moveWordLeftAndModifySelection:self];
+ newStartRange = [self selectedRange].location;
+ newEndRange = newStartRange + [self selectedRange].length;
}
- if([[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound)
+ // how many space in front of the selection
+ int bias = [self selectedRange].length - [[[[self string] substringWithRange:[self selectedRange]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length];
+ [self setSelectedRange:NSMakeRange([self selectedRange].location+bias, [self selectedRange].length-bias)];
+ newStartRange += bias;
+ newEndRange -= bias;
+
+ // is caret inside the selection still?
+ if(curLocation < newStartRange || curLocation > newEndRange
+ || [[[self string] substringWithRange:[self selectedRange]] rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location != NSNotFound)
[self setSelectedRange:curRange];
NSRange wordRange = [self selectedRange];