aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-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];