From 5c01336855fde8694dfe2c9060c7e8f43b61d950 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 27 Jan 2010 14:30:28 +0000 Subject: =?UTF-8?q?=E2=80=A2=20query=20favorite=20snippet=20session=20(tex?= =?UTF-8?q?t=20macro)=20-=20draw=20a=20bezier=20path=20around=20defined=20?= =?UTF-8?q?snippets=20to=20group=20them=20graphically=20(test=20phase)=20-?= =?UTF-8?q?=20allow=20the=20user=20to=20go=20into=20a=20snippet=20by=20usi?= =?UTF-8?q?ng=20the=20mouse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Source/CMTextView.m b/Source/CMTextView.m index fe1af726..eb2abff4 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -1092,8 +1092,33 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } } } + // If caret is not inside the current snippet range check if caret is inside of + // another defined snippet; if so set currentSnippetIndex to it (this allows to use the + // mouse to activate another snippet). If the caret is inside of overlapped snippets (nested) + // then select this snippet which has the smallest length. if(!isCaretInsideASnippet && foundSnippetIndices[currentSnippetIndex] == 1) { isCaretInsideASnippet = YES; + } else { + NSInteger index = -1; + NSInteger smallestLength = -1; + for(i=0; i snippetControlArray[i][1]) { + index = i; + smallestLength = snippetControlArray[i][1]; + } + } + } + } + // Reset the active snippet + if(index > -1 && smallestLength > -1) { + currentSnippetIndex = index; + isCaretInsideASnippet = YES; + } } return isCaretInsideASnippet; @@ -2838,6 +2863,29 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } +- (void)drawRect:(NSRect)rect { + + [super drawRect:rect]; + + // Highlight snippets coming from the Query Favorite text macro + if(snippetControlCounter > -1) { + NSInteger i; + [[NSColor colorWithCalibratedRed:0.0 green:0.5 blue:0.0 alpha:0.1] setFill]; + for(i=0; i -1) { + NSRange glRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(snippetControlArray[i][0],snippetControlArray[i][1]) actualCharacterRange:NULL]; + if(glRange.length) { + NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glRange inTextContainer:[self textContainer]]; + boundingRect = NSInsetRect(boundingRect, 0, 2); + NSBezierPath *aBezierPath = [NSBezierPath bezierPathWithRoundedRect:boundingRect xRadius:4 yRadius:15]; + [aBezierPath fill]; + } + } + } + } +} + + #pragma mark - #pragma mark context menu @@ -2996,7 +3044,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // Re-calculate snippet ranges if snippet session is active if(snippetControlCounter > -1 && !snippetWasJustInserted) { - + if([self checkForCaretInsideSnippet]) { NSInteger editStartPosition = [textStore editedRange].location; -- cgit v1.2.3