diff options
-rw-r--r-- | Source/SPNarrowDownCompletion.h | 3 | ||||
-rw-r--r-- | Source/SPNarrowDownCompletion.m | 18 | ||||
-rw-r--r-- | Source/SPTextView.m | 6 |
3 files changed, 19 insertions, 8 deletions
diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h index 7b33dea0..192bbf38 100644 --- a/Source/SPNarrowDownCompletion.h +++ b/Source/SPNarrowDownCompletion.h @@ -55,6 +55,7 @@ NSRange theCharRange; NSRange theParseRange; NSString *theDbName; + NSString *theAliasName; NSTimer *stateTimer; NSArray *syncArrowImages; @@ -78,7 +79,7 @@ dictMode:(BOOL)mode dbMode:(BOOL)theDbMode tabTriggerMode:(BOOL)tabTriggerMode fuzzySearch:(BOOL)fuzzySearch backtickMode:(NSInteger)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName selectedDb:(NSString*)selectedDb caretMovedLeft:(BOOL)caretMovedLeft autoComplete:(BOOL)autoComplete oneColumn:(BOOL)oneColumn - isQueryingDBStructure:(BOOL)isQueryingDBStructure; + alias:(NSString*)anAlias isQueryingDBStructure:(BOOL)isQueryingDBStructure; - (void)setCaretPos:(NSPoint)aPos; - (void)insert_text:(NSString* )aString; - (void)insertAutocompletePlaceholder; diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index b0c2bc02..abc00d9a 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -215,7 +215,7 @@ dictMode:(BOOL)mode dbMode:(BOOL)theDbMode tabTriggerMode:(BOOL)tabTriggerMode fuzzySearch:(BOOL)fuzzySearch backtickMode:(NSInteger)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName selectedDb:(NSString*)selectedDb caretMovedLeft:(BOOL)caretMovedLeft autoComplete:(BOOL)autoComplete oneColumn:(BOOL)oneColumn - isQueryingDBStructure:(BOOL)isQueryingDBStructure + alias:(NSString*)anAlias isQueryingDBStructure:(BOOL)isQueryingDBStructure { if(self = [self init]) { @@ -228,6 +228,7 @@ autoCompletionMode = autoComplete; + theAliasName = anAlias; oneColumnMode = oneColumn; isQueryingDatabaseStructure = isQueryingDBStructure; @@ -1030,12 +1031,17 @@ [theView setSelectedRange:r]; else { if(backtickMode == 100) { - BOOL nextCharIsBacktick = ([[[theView string] substringWithRange:theCharRange] hasSuffix:@"`"]); + NSString *replaceString = [[theView string] substringWithRange:theCharRange]; + BOOL nextCharIsBacktick = ([replaceString hasSuffix:@"`"]); if(theCharRange.length == 1) nextCharIsBacktick = NO; - if(!nextCharIsBacktick) - [theView setSelectedRange:NSMakeRange(theCharRange.location, theCharRange.length+2)]; - else + if(!nextCharIsBacktick) { + if([replaceString hasPrefix:@"`"]) + [theView setSelectedRange:NSMakeRange(theCharRange.location, theCharRange.length+2)]; + else + [theView setSelectedRange:theCharRange]; + } else { [theView setSelectedRange:theCharRange]; + } backtickMode = 0; } else [theView setSelectedRange:theCharRange]; @@ -1073,7 +1079,7 @@ NSString* candidateMatch = [selectedItem objectForKey:@"match"] ?: [selectedItem objectForKey:@"display"]; if([selectedItem objectForKey:@"isRef"] && ([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask)) - && [[selectedItem objectForKey:@"path"] length]) { + && [[selectedItem objectForKey:@"path"] length] && theAliasName == nil) { NSString *path = [[[selectedItem objectForKey:@"path"] componentsSeparatedByString:SPUniqueSchemaDelimiter] componentsJoinedByPeriodAndBacktickQuotedAndIgnoreFirst]; // Check if path's db name is the current selected db name diff --git a/Source/SPTextView.m b/Source/SPTextView.m index b4090cb9..41b5d6e4 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -773,6 +773,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) object:nil]; // Check for table name aliases + NSString *alias = nil; if(dbBrowseMode && tableDocumentInstance && customQueryInstance) { NSString *theDb = (dbName == nil) ? [NSString stringWithString:currentDb] : [NSString stringWithString:dbName]; NSString *connectionID = [tableDocumentInstance connectionID]; @@ -788,7 +789,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) for(NSString* m in matches) { NSRange aliasRange = [m rangeOfRegex:re capture:1L]; if(aliasRange.length) { - NSString *alias = [[m substringWithRange:aliasRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"]; + alias = [[m substringWithRange:aliasRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"]; // If alias refers to db.table split and check it if([alias rangeOfString:@"."].length) { NSRange dbRange = [alias rangeOfRegex:@"^`?(.*?)`?\\." capture:1L]; @@ -838,6 +839,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) caretMovedLeft:caretMovedLeft autoComplete:autoCompleteMode oneColumn:isDictMode + alias:alias isQueryingDBStructure:[mySQLConnection isQueryingDatabaseStructure]]; completionParseRangeLocation = parseRange.location; @@ -1460,6 +1462,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) caretMovedLeft:NO autoComplete:NO oneColumn:NO + alias:nil isQueryingDBStructure:NO]; //Get the NSPoint of the first character of the current word @@ -1616,6 +1619,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) caretMovedLeft:NO autoComplete:NO oneColumn:YES + alias:nil isQueryingDBStructure:NO]; //Get the NSPoint of the first character of the current word |