diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-03-08 22:12:13 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-03-08 22:12:13 +0000 |
commit | eaa7c5890efffcabf485241caad1198c73dca060 (patch) | |
tree | d743f5fb0f7beade63ae54e4bdd9d81622d3a7ab /Source/CMTextView.m | |
parent | e819de7f2889a25d3bc7c569b3fdee2f1551c61a (diff) | |
download | sequelpro-eaa7c5890efffcabf485241caad1198c73dca060.tar.gz sequelpro-eaa7c5890efffcabf485241caad1198c73dca060.tar.bz2 sequelpro-eaa7c5890efffcabf485241caad1198c73dca060.zip |
• added possibility to define a snippet via ¦a¦b¦ – such a snippet will be shown as completion list with the items “a” and “b”
• set auto-completion default Pref setting to true
• fixed some auto-completion issues like do not insert common prefix automatically and some others
• applied ¦a¦b¦ template to CompletionTokens.plist and some tiny corrections and improvements
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r-- | Source/CMTextView.m | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 32434682..b21b65ee 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -715,7 +715,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [completionPopUp setCaretPos:pos]; completionIsOpen = YES; [completionPopUp orderFront:self]; - [completionPopUp insertCommonPrefix]; + if(!autoCompleteMode) + [completionPopUp insertCommonPrefix]; } @@ -1103,10 +1104,48 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if(snippetControlArray[currentSnippetIndex][2] == 0) { 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) + if(r1.location == r2.location && r1.length == r2.length) { [self setSelectedRange:r2]; - else + NSString *snip = [[self string] substringWithRange:r2]; + if([snip length] > 2 && [snip hasPrefix:@"¦"] && [snip hasSuffix:@"¦"]) { + NSArray *list = [[snip substringWithRange:NSMakeRange(1,[snip length]-2)] componentsSeparatedByString:@"¦"]; + NSMutableArray *possibleCompletions = [[[NSMutableArray alloc] initWithCapacity:[list count]] autorelease]; + for(id w in list) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:w, @"display", @"dummy-small", @"image", nil]]; + + SPNarrowDownCompletion* completionPopUp = [[SPNarrowDownCompletion alloc] initWithItems:possibleCompletions + alreadyTyped:@"" + staticPrefix:@"" + additionalWordCharacters:@"_." + caseSensitive:NO + charRange:r2 + parseRange:r2 + inView:self + dictMode:NO + dbMode:NO + tabTriggerMode:[self isSnippetMode] + fuzzySearch:NO + backtickMode:NO + withDbName:@"" + withTableName:@"" + selectedDb:@"" + caretMovedLeft:NO + autoComplete:NO]; + + //Get the NSPoint of the first character of the current word + NSRange glyphRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(r2.location,1) actualCharacterRange:NULL]; + NSRect boundingRect = [[self layoutManager] boundingRectForGlyphRange:glyphRange inTextContainer:[self textContainer]]; + boundingRect = [self convertRect: boundingRect toView: NULL]; + NSPoint pos = [[self window] convertBaseToScreen: NSMakePoint(boundingRect.origin.x + boundingRect.size.width,boundingRect.origin.y + boundingRect.size.height)]; + // Adjust list location to be under the current word or insertion point + pos.y -= [[self font] pointSize]*1.25; + [completionPopUp setCaretPos:pos]; + completionIsOpen = YES; + [completionPopUp orderFront:self]; + } + } else { [self endSnippetSession]; + } } } else { // for safety reasons [self endSnippetSession]; |