aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-17 10:54:27 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-17 10:54:27 +0000
commit183ac8ed6f065c99de2911df97f4285ed21bbcca (patch)
tree024f55f8bafe7793d6561fce33baaa6e116e41c0
parent8317097106e89ca010bee9771bd0c1f6d53754b8 (diff)
downloadsequelpro-183ac8ed6f065c99de2911df97f4285ed21bbcca.tar.gz
sequelpro-183ac8ed6f065c99de2911df97f4285ed21bbcca.tar.bz2
sequelpro-183ac8ed6f065c99de2911df97f4285ed21bbcca.zip
- fixed bug for nested snippets if a nested snippet is located at the very end of the text buffer and has no default value
- added a range sanity check for completion before insertion of the chosen item
-rw-r--r--Source/CMTextView.m11
-rw-r--r--Source/SPNarrowDownCompletion.m4
2 files changed, 14 insertions, 1 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index bfc119bd..17720a03 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -1356,8 +1356,17 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if(currentSnippetIndex >= 0 && currentSnippetIndex < 20) {
if(snippetControlArray[currentSnippetIndex][2] == 0) {
+
NSRange r1 = NSMakeRange(snippetControlArray[currentSnippetIndex][0], snippetControlArray[currentSnippetIndex][1]);
- NSRange r2 = NSIntersectionRange(NSMakeRange(0,[[self string] length]), r1);
+
+ NSRange r2;
+ // Ensure the selection for nested snippets if it is at very end of the text buffer
+ // because NSIntersectionRange returns {0, 0} in such a case
+ if(r1.location == [[self string] length])
+ r2 = NSMakeRange([[self string] length], 0);
+ else
+ r2 = NSIntersectionRange(NSMakeRange(0,[[self string] length]), r1);
+
if(r1.location == r2.location && r1.length == r2.length) {
[self setSelectedRange:r2];
NSString *snip = [[self string] substringWithRange:r2];
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index ac29fc08..cfdd7605 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -759,6 +759,10 @@
- (void)insert_text:(NSString* )aString
{
+ // Ensure that theCharRange is valid
+ if(NSMaxRange(theCharRange) > [[theView string] length])
+ theCharRange = NSIntersectionRange(NSMakeRange(0,[[theView string] length]), theCharRange);
+
NSRange r = [theView selectedRange];
if(r.length)
[theView setSelectedRange:r];