From c316e723764eba6141456acb8a61a4cdfcf68e62 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 29 Jan 2010 16:10:14 +0000 Subject: =?UTF-8?q?=E2=80=A2=20text=20macro=20logic=20-=20improved=20highl?= =?UTF-8?q?ighting=20of=20multi-line=20snippets=20(many=20thanks=20to=20ja?= =?UTF-8?q?bakobob=20for=20this=20patch!)=20-=20some=20tiny=20cosmetics=20?= =?UTF-8?q?=E2=80=A2=20error=20message=20highlighting=20in=20Custom=20Quer?= =?UTF-8?q?y=20Editor=20-=20removed=20near=20message=20length=20checking?= =?UTF-8?q?=20to=20be=20larger=20than=202,=20not=20necessary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'Source/CMTextView.m') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 2bc01fcd..55e6d4e1 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -935,7 +935,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if(currentSnippetIndex >= 0 && currentSnippetIndex < 20) { if(snippetControlArray[currentSnippetIndex][2] == 0) { - [self setSelectedRange:NSMakeRange(snippetControlArray[currentSnippetIndex][0], snippetControlArray[currentSnippetIndex][1])]; + NSRange r1 = NSMakeRange(snippetControlArray[currentSnippetIndex][0], snippetControlArray[currentSnippetIndex][1]); + NSRange r2 = NSIntersectionRange(NSMakeRange(0,[[self string] length]), r1); + if(r1.location == r2.location && r1.length == r2.length) + [self setSelectedRange:r2]; + else + [self endSnippetSession]; } } else { // for safety reasons [self endSnippetSession]; @@ -1104,8 +1109,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) return NO; } - [[self textStorage] ensureAttributesAreFixedInRange:[self selectedRange]]; - NSInteger caretPos = [self selectedRange].location; NSInteger i, j; NSInteger foundSnippetIndices[20]; // array to hold nested snippets @@ -2916,20 +2919,27 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSInteger i; for(i=0; i -1) { - NSRange glRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(snippetControlArray[i][0],snippetControlArray[i][1]) actualCharacterRange:NULL]; - NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glRange inTextContainer:[self textContainer]]; - if(!glRange.length) boundingRect.size.width = 1; - boundingRect = NSInsetRect(boundingRect, -4, 0.2); - NSBezierPath *aBezierPath = [NSBezierPath bezierPathWithRoundedRect:boundingRect xRadius:6 yRadius:10]; - if(i == currentSnippetIndex) - [[NSColor colorWithCalibratedRed:1.0 green:0.6 blue:0.0 alpha:0.7] setFill]; - else - [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:0.4] setFill]; - [aBezierPath fill]; - boundingRect = NSInsetRect(boundingRect, 1.3, 1.3); - aBezierPath = [NSBezierPath bezierPathWithRoundedRect:boundingRect xRadius:6 yRadius:10]; - [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:0.8] setFill]; - [aBezierPath fill]; + NSUInteger rectCount; + NSRange snippetRange = NSMakeRange(snippetControlArray[i][0],snippetControlArray[i][1]); + NSRectArray snippetRects = [[self layoutManager] rectArrayForCharacterRange: snippetRange + withinSelectedCharacterRange: snippetRange + inTextContainer: [self textContainer] + rectCount: &rectCount ]; + for (NSUInteger j=0; j