From 7f8b4675de74f7b43057d21d445f0ddca59f95b8 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 8 Mar 2010 13:02:05 +0000 Subject: =?UTF-8?q?=E2=80=A2=20outsourced=20keyword=20completion=20and=20f?= =?UTF-8?q?unction=20completion=20lists=20to=20CompletionTokens.plist=20?= =?UTF-8?q?=E2=80=A2=20SPQueryController=20manages=20keyword=20and=20funct?= =?UTF-8?q?ion=20completion=20lists=20now;=20this=20reduces=20the=20memory?= =?UTF-8?q?=20usage=20a=20bit=20and=20the=20list=20is=20easier=20to=20edit?= =?UTF-8?q?=20=E2=80=A2=20added=20pre-defined=20function=20argument=20snip?= =?UTF-8?q?pets=20to=20CompletionTokens.plist=20(auto-generated=20from=20m?= =?UTF-8?q?ysql's=20HELP)=20=E2=80=A2=20added=20Preference=20option=20for?= =?UTF-8?q?=20Editor=20whether=20a=20function=20completion=20should=20inse?= =?UTF-8?q?rt=20()=20and=20if=20found=20the=20function=20argument=20snippe?= =?UTF-8?q?ts=20automatically=20or=20not=20-=20last=20)=20will=20be=20link?= =?UTF-8?q?ed=20as=20autopaired=20then=20=E2=80=A2=20changed=20behaviour?= =?UTF-8?q?=20for=20wrapping=20a=20selection=20into=20`"'()=20etc.=20-=20n?= =?UTF-8?q?ow=20it=20re-selects=20the=20original=20selection=20after=20wra?= =?UTF-8?q?pping=20and=20in=20addition=20last=20wrap=20character=20is=20no?= =?UTF-8?q?w=20marked=20as=20autopair-linked=20=E2=80=A2=20improved=20logi?= =?UTF-8?q?c=20for=20popping=20up=20the=20auto-completion=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPNarrowDownCompletion.m | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'Source/SPNarrowDownCompletion.m') diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index 3df3d7b6..10d4c1f7 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -33,6 +33,7 @@ #import "SPStringAdditions.h" #import "ImageAndTextCell.h" #import "SPConstants.h" +#import "SPQueryController.h" #import "RegexKitLite.h" #import "CMTextView.h" #include @@ -112,6 +113,8 @@ filtered = nil; spaceCounter = 0; + prefs = [NSUserDefaults standardUserDefaults]; + tableFont = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:SPCustomQueryEditorFont]]; [self setupInterface]; } @@ -451,11 +454,15 @@ closeMe = YES; return; } else { + if([theView completionWasReinvokedAutomatically]) return; if([[self filterString] hasSuffix:@"."]) { + [theView setCompletionWasReinvokedAutomatically:YES]; [theView doCompletionByUsingSpellChecker:dictMode fuzzyMode:fuzzyMode autoCompleteMode:NO]; closeMe = YES; + return; + } else { + [newFiltered addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"No completions found", @"no completions found message"), @"display", @"", @"noCompletion", nil]]; } - [newFiltered addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"No completions found", @"no completions found message"), @"display", @"", @"noCompletion", nil]]; } } @@ -656,15 +663,15 @@ [commonPrefix setString:tempPrefix]; } - // if(![commonPrefix length]) return; - - NSString* toInsert = [commonPrefix substringFromIndex:[[self filterString] length]]; - [mutablePrefix appendString:toInsert]; - theCharRange.length += [toInsert length]; - theParseRange.length += [toInsert length]; - [theView insertText:[toInsert lowercaseString]]; - [self checkSpaceForAllowedCharacter]; - + // Insert common prefix automatically + if([[self filterString] length] < [commonPrefix length]) { + NSString* toInsert = [commonPrefix substringFromIndex:[[self filterString] length]]; + [mutablePrefix appendString:toInsert]; + theCharRange.length += [toInsert length]; + theParseRange.length += [toInsert length]; + [theView insertText:[toInsert lowercaseString]]; + [self checkSpaceForAllowedCharacter]; + } } - (void)insert_text:(NSString* )aString @@ -675,11 +682,12 @@ // If completion string contains backticks move caret out of the backticks if(backtickMode && !triggerMode) [theView performSelector:@selector(moveRight:)]; - // If it's a function insert () snippet - else if([[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"func"] && ![aString hasSuffix:@")"]) { - [theView insertText:@"()"]; - [theView performSelector:@selector(moveLeft:)]; - // [theView insertAsSnippet:@"(${1:})" atRange:[theView selectedRange]]; + // If it's a function insert () and if given arguments as snippets + else if([prefs boolForKey:SPCustomQueryFunctionCompletionInsertsArguments] && [[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"func"] && ![aString hasSuffix:@")"]) { + NSString *functionArgumentSnippet = [NSString stringWithFormat:@"(%@)", [[SPQueryController sharedQueryController] argumentSnippetForFunction:aString]]; + [theView insertAsSnippet:functionArgumentSnippet atRange:[theView selectedRange]]; + if([functionArgumentSnippet length] == 2) + [theView performSelector:@selector(moveLeft:)]; } } -- cgit v1.2.3