aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMTextView.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-04-08 18:58:43 +0000
committerBibiko <bibiko@eva.mpg.de>2009-04-08 18:58:43 +0000
commit1e7eec7003844f7ff503fe7bf8f4f405df4563f4 (patch)
tree3ed6d69fc23acb9534984d319e5614db4ef2d828 /Source/CMTextView.m
parent0d1cb713dd4ad473db2b3a2940e78cbfe134fead (diff)
downloadsequelpro-1e7eec7003844f7ff503fe7bf8f4f405df4563f4.tar.gz
sequelpro-1e7eec7003844f7ff503fe7bf8f4f405df4563f4.tar.bz2
sequelpro-1e7eec7003844f7ff503fe7bf8f4f405df4563f4.zip
• FIXED: unique completion list
• ADDED: if caret is inside quotes "" or '' show Apple's default completion list due to the spell checker settings
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r--Source/CMTextView.m47
1 files changed, 34 insertions, 13 deletions
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 ];
}
}