diff options
author | stuconnolly <stuart02@gmail.com> | 2011-01-27 20:38:23 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2011-01-27 20:38:23 +0000 |
commit | 8db2f78294982e89fce5a162d92b2be6d9291aa1 (patch) | |
tree | b8dc7736f4af896aa3ed3fa9a96d1f3c4bfd0e59 /Source/SPTextViewAdditions.m | |
parent | fa7cff57548edc51420693e6909fe2adb3c18951 (diff) | |
parent | 7cc062247ff23496dd0390cf07b5d45d6bc49777 (diff) | |
download | sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.tar.gz sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.tar.bz2 sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.zip |
Bring outline view branch up to date with trunk (r3056:r3162).
Diffstat (limited to 'Source/SPTextViewAdditions.m')
-rw-r--r-- | Source/SPTextViewAdditions.m | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 2e1f8f9b..9cefa758 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -41,41 +41,34 @@ if (curRange.length) return curRange; - NSUInteger curLocation = curRange.location; + NSInteger curLocation = curRange.location; + NSInteger start = curLocation; + NSInteger end = curLocation; + NSUInteger strLen = [[self string] length]; + + NSMutableCharacterSet *wordCharSet = [NSMutableCharacterSet alphanumericCharacterSet]; + [wordCharSet addCharactersInString:@"_."]; + [wordCharSet removeCharactersInString:@"`"]; + + if(start) { + start--; + while([wordCharSet characterIsMember:[[self string] characterAtIndex:start]]) { + start--; + if(start < 0) break; + } + start++; + } - [self moveWordLeft:self]; - [self moveWordRightAndModifySelection:self]; - - NSUInteger newStartRange = [self selectedRange].location; - NSUInteger newEndRange = newStartRange + [self selectedRange].length; - - // if current location does not intersect with found range - // then caret is at the begin of a word -> change strategy - if(curLocation < newStartRange || curLocation > newEndRange) - { - [self setSelectedRange:curRange]; - [self moveWordRight:self]; - [self moveWordLeftAndModifySelection:self]; - newStartRange = [self selectedRange].location; - newEndRange = newStartRange + [self selectedRange].length; + while(end < strLen && [wordCharSet characterIsMember:[[self string] characterAtIndex:end]]) { + end++; } - - // how many space in front of the selection - NSInteger 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]; - - [self setSelectedRange:curRange]; - + + NSRange wordRange = NSMakeRange(start, end-start); + if(wordRange.length && [[self string] characterAtIndex:NSMaxRange(wordRange)-1] == '.') + wordRange.length--; + return(wordRange); + } /* @@ -534,7 +527,7 @@ [[NSFileManager defaultManager] removeItemAtPath:bundleInputFilePath error:nil]; - BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"] && [self respondsToSelector:@selector(currentQueryRange)]) ; + BOOL selfIsQueryEditor = ([[[self class] description] isEqualToString:@"SPTextView"] && [[self delegate] respondsToSelector:@selector(currentQueryRange)]); if([cmdData objectForKey:SPBundleFileInputSourceKey]) inputAction = [[cmdData objectForKey:SPBundleFileInputSourceKey] lowercaseString]; @@ -562,7 +555,7 @@ replaceRange = currentLineRange; else if([inputFallBackAction isEqualToString:SPBundleInputSourceCurrentQuery]) replaceRange = currentQueryRange; - else if([inputAction isEqualToString:SPBundleInputSourceEntireContent]) + else if([inputFallBackAction isEqualToString:SPBundleInputSourceEntireContent]) replaceRange = NSMakeRange(0,[[self string] length]); } else { replaceRange = currentSelectionRange; @@ -622,8 +615,11 @@ if(currentLineRange.length) [env setObject:[[self string] substringWithRange:currentLineRange] forKey:SPBundleShellVariableCurrentLine]; + [env setObject:NSStringFromRange(replaceRange) forKey:SPBundleShellVariableSelectedTextRange]; + NSError *inputFileError = nil; NSString *input = [NSString stringWithString:[[self string] substringWithRange:replaceRange]]; + [input writeToFile:bundleInputFilePath atomically:YES encoding:NSUTF8StringEncoding @@ -739,8 +735,9 @@ } else if([action isEqualToString:SPBundleOutputActionReplaceSelection]) { - [self shouldChangeTextInRange:replaceRange replacementString:output]; - [self replaceCharactersInRange:replaceRange withString:output]; + NSRange safeRange = NSIntersectionRange(replaceRange, NSMakeRange(0, [[self string] length])); + [self shouldChangeTextInRange:safeRange replacementString:output]; + [self replaceCharactersInRange:safeRange withString:output]; } } else { |