diff options
-rw-r--r-- | Source/CMTextView.m | 5 | ||||
-rw-r--r-- | Source/SPEditorTokens.l | 6 | ||||
-rw-r--r-- | Source/SPNarrowDownCompletion.h | 3 | ||||
-rw-r--r-- | Source/SPNarrowDownCompletion.m | 22 |
4 files changed, 28 insertions, 8 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 86e6955f..8346525b 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -230,6 +230,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if([self getRangeForCurrentWord].length) isDictMode = ([[[self textStorage] attribute:kQuote atIndex:[self getRangeForCurrentWord].location effectiveRange:nil] isEqualToString:kQuoteValue] ); + BOOL dbStructureMode = ([[[self textStorage] attribute:kBTQuote atIndex:[self selectedRange].location-1 effectiveRange:nil] isEqualToString:kBTQuoteValue]) ? YES : NO; + // Refresh quote attributes [[self textStorage] removeAttribute:kQuote range:NSMakeRange(0,[[self string] length])]; // [self insertText:@""]; @@ -246,7 +248,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) caseSensitive:!caseInsensitive charRange:[self getRangeForCurrentWord] inView:self - dictMode:isDictMode]; + dictMode:isDictMode + dbMode:dbStructureMode]; //Get the NSPoint of the first character of the current word NSRange range = NSMakeRange([self getRangeForCurrentWord].location,0); diff --git a/Source/SPEditorTokens.l b/Source/SPEditorTokens.l index 3da0ce55..9d9cf50b 100644 --- a/Source/SPEditorTokens.l +++ b/Source/SPEditorTokens.l @@ -37,8 +37,8 @@ */ #import "SPEditorTokens.h" -int utf8strlen(const char * _s); -int yyuoffset, yyuleng; +size_t utf8strlen(const char * _s); +size_t yyuoffset, yyuleng; #define YY_NO_UNPUT @@ -112,7 +112,7 @@ keywords (X(OR|509|A)|S(MALLINT|SL|H(OW({s}(E(NGINE(S)?|RRORS)|M(ASTER|UTEX)|BIN #define ONEMASK ((size_t)(-1) / 0xFF) // adapted from http://www.daemonology.net/blog/2008-06-05-faster-utf8-strlen.html -int utf8strlen(const char * _s) +size_t utf8strlen(const char * _s) { const char * s; size_t count = 0; diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h index bfff4d21..1a0359eb 100644 --- a/Source/SPNarrowDownCompletion.h +++ b/Source/SPNarrowDownCompletion.h @@ -42,6 +42,7 @@ BOOL closeMe; BOOL caseSensitive; BOOL dictMode; + BOOL dbStructureMode; NSFont *tableFont; NSRange theCharRange; NSArray *words; @@ -50,7 +51,7 @@ NSMutableCharacterSet* textualInputCharacters; } -- (id)initWithItems:(NSArray*)someSuggestions alreadyTyped:(NSString*)aUserString staticPrefix:(NSString*)aStaticPrefix additionalWordCharacters:(NSString*)someAdditionalWordCharacters caseSensitive:(BOOL)isCaseSensitive charRange:(NSRange)initRange inView:(id)aView dictMode:(BOOL)mode; +- (id)initWithItems:(NSArray*)someSuggestions alreadyTyped:(NSString*)aUserString staticPrefix:(NSString*)aStaticPrefix additionalWordCharacters:(NSString*)someAdditionalWordCharacters caseSensitive:(BOOL)isCaseSensitive charRange:(NSRange)initRange inView:(id)aView dictMode:(BOOL)mode dbMode:(BOOL)dbMode; - (void)setCaretPos:(NSPoint)aPos; - (void)insert_text:(NSString* )aString; diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index a4daefa0..090319dc 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -124,19 +124,30 @@ [super dealloc]; } -- (id)initWithItems:(NSArray*)someSuggestions alreadyTyped:(NSString*)aUserString staticPrefix:(NSString*)aStaticPrefix additionalWordCharacters:(NSString*)someAdditionalWordCharacters caseSensitive:(BOOL)isCaseSensitive charRange:(NSRange)initRange inView:(id)aView dictMode:(BOOL)mode +- (id)initWithItems:(NSArray*)someSuggestions alreadyTyped:(NSString*)aUserString staticPrefix:(NSString*)aStaticPrefix additionalWordCharacters:(NSString*)someAdditionalWordCharacters caseSensitive:(BOOL)isCaseSensitive charRange:(NSRange)initRange inView:(id)aView dictMode:(BOOL)mode dbMode:(BOOL)dbMode { if(self = [self init]) { - if(aUserString && ![aUserString isEqualToString:@"`"]) + BOOL filterStringIsBacktick = ([aUserString isEqualToString:@"`"]) ? YES : NO; + + // Set filter string - if aUserString == ` user invoked it via `|` ie show all db/tables/fields etc. + if(aUserString && !filterStringIsBacktick) [mutablePrefix appendString:aUserString]; + dbStructureMode = dbMode; + if(aStaticPrefix) staticPrefix = [aStaticPrefix retain]; caseSensitive = isCaseSensitive; + theCharRange = initRange; + if(filterStringIsBacktick) { + theCharRange.length = 0; + theCharRange.location++; + } + theView = aView; dictMode = mode; @@ -474,7 +485,9 @@ if([[self filterString] length] < [commonPrefix length]) { - [self insert_text:commonPrefix]; + [theView setSelectedRange:theCharRange]; + [theView insertText:commonPrefix]; + NSString* toInsert = [commonPrefix substringFromIndex:[[self filterString] length]]; [mutablePrefix appendString:toInsert]; theCharRange = NSMakeRange(theCharRange.location,[commonPrefix length]); @@ -491,6 +504,8 @@ { [theView setSelectedRange:theCharRange]; [theView insertText:aString]; + if(dbStructureMode) + [theView performSelector:@selector(moveRight:)]; } - (void)completeAndInsertSnippet @@ -505,6 +520,7 @@ NSString* candidateMatch = [selectedItem objectForKey:@"match"] ?: [selectedItem objectForKey:@"display"]; if([[self filterString] length] < [candidateMatch length]) [self insert_text:candidateMatch]; + } closeMe = YES; } |