From 1e7eec7003844f7ff503fe7bf8f4f405df4563f4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 8 Apr 2009 18:58:43 +0000 Subject: =?UTF-8?q?=E2=80=A2=20FIXED:=20unique=20completion=20list=20?= =?UTF-8?q?=E2=80=A2=20ADDED:=20if=20caret=20is=20inside=20quotes=20""=20o?= =?UTF-8?q?r=20''=20show=20Apple's=20default=20completion=20list=20due=20t?= =?UTF-8?q?o=20the=20spell=20checker=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 2a523de9..b61159f7 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -39,6 +39,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); #define kWQquoted @"Quoted" // set via lex to indicate a quoted string #define kWQval @"quoted" #define kSQLkeyword @"SQLkw" // attribute for found SQL keywords +#define kQuote @"Quote" @implementation CMTextView @@ -485,10 +486,20 @@ YY_BUFFER_STATE yy_scan_string (const char *); - (NSArray *)completionsForPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index { + // Check if the caret is inside quotes "" or ''; if so + // return the normal word suggestion due to the spelling's language + if([[self textStorage] attribute:kQuote atIndex:charRange.location effectiveRange:nil]) + { + NSSpellChecker* checker = [NSSpellChecker sharedSpellChecker]; + NSArray* list = [checker completionsForPartialWordRange:NSMakeRange(0,charRange.length) inString:[[self string] substringWithRange:charRange] language:nil inSpellDocumentWithTag:0]; + return list; + } + NSCharacterSet *separators = [NSCharacterSet characterSetWithCharactersInString:@" \t\r\n,()\"'`-!"]; - NSArray *textViewWords = [[self string] componentsSeparatedByCharactersInSet:separators]; - NSString *partialString = [[self string] substringWithRange:charRange]; + NSArray *textViewWords = [[self string] componentsSeparatedByCharactersInSet:separators]; + NSString *partialString = [[self string] substringWithRange:charRange]; unsigned int partialLength = [partialString length]; + id tableNames = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"tables"]; //unsigned int options = NSCaseInsensitiveSearch | NSAnchoredSearch; @@ -508,21 +519,25 @@ YY_BUFFER_STATE yy_scan_string (const char *); NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@ AND length > %d", partialString, partialLength]; NSArray *matchingCompletions = [[possibleCompletions filteredArrayUsingPredicate:predicate] sortedArrayUsingSelector:@selector(compare:)]; + + unsigned i, insindex; insindex = 0; - for (i = 0; i < [matchingCompletions count]; i ++) + for (i = 0; i < [matchingCompletions count]; i++) { - if ([partialString isEqualToString:[[matchingCompletions objectAtIndex:i] substringToIndex:partialLength]]) - { - // Matches case --> Insert at beginning of completion list - [compl insertObject:[matchingCompletions objectAtIndex:i] atIndex:insindex++]; - } - else - { - // Not matching case --> Insert at end of completion list - [compl addObject:[matchingCompletions objectAtIndex:i]]; - } + NSString* obj = [matchingCompletions objectAtIndex:i]; + if(![compl containsObject:obj]) + if ([partialString isEqualToString:[obj substringToIndex:partialLength]]) + { + // Matches case --> Insert at beginning of completion list + [compl insertObject:obj atIndex:insindex++]; + } + else + { + // Not matching case --> Insert at end of completion list + [compl addObject:obj]; + } } return [compl autorelease]; @@ -1025,6 +1040,12 @@ SYNTAX HIGHLIGHTING! [textStore addAttribute: kSQLkeyword value: kWQval range: tokenRange ]; + // Add an attribute to be used to distinguish quotes from keywords etc. + // used e.g. in completion suggestions + if(token == SPT_DOUBLE_QUOTED_TEXT || token == SPT_SINGLE_QUOTED_TEXT) + [textStore addAttribute: kQuote + value: kWQval + range: tokenRange ]; } } -- cgit v1.2.3