From eaa7c5890efffcabf485241caad1198c73dca060 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 8 Mar 2010 22:12:13 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20possibility=20to=20define=20a=20sni?= =?UTF-8?q?ppet=20via=20=C2=A6a=C2=A6b=C2=A6=20=E2=80=93=20such=20a=20snip?= =?UTF-8?q?pet=20will=20be=20shown=20as=20completion=20list=20with=20the?= =?UTF-8?q?=20items=20=E2=80=9Ca=E2=80=9D=20and=20=E2=80=9Cb=E2=80=9D=20?= =?UTF-8?q?=E2=80=A2=20set=20auto-completion=20default=20Pref=20setting=20?= =?UTF-8?q?to=20true=20=E2=80=A2=20fixed=20some=20auto-completion=20issues?= =?UTF-8?q?=20like=20do=20not=20insert=20common=20prefix=20automatically?= =?UTF-8?q?=20and=20some=20others=20=E2=80=A2=20applied=20=C2=A6a=C2=A6b?= =?UTF-8?q?=C2=A6=20template=20to=20CompletionTokens.plist=20and=20some=20?= =?UTF-8?q?tiny=20corrections=20and=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 45 ++++++++++++++++++++++++++++++++++++++--- Source/SPNarrowDownCompletion.m | 2 +- 2 files changed, 43 insertions(+), 4 deletions(-) (limited to 'Source') 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]; diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index 10d4c1f7..9f539d67 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -574,7 +574,7 @@ break; } } - else if(key == NSCarriageReturnCharacter || key == NSTabCharacter) + else if(key == NSCarriageReturnCharacter || (key == NSTabCharacter && !triggerMode)) { [self completeAndInsertSnippet]; } -- cgit v1.2.3